由于您不喜欢我对程序的解释,因此我现在仅将其更改为一个问题:我如何允许程序继续检查输入内容并根据输出结果输入mu来应用规则
x = input("Enter your string: ")
while not set(x).issubset({'m', 'u', 'i'}):
print("false")
x = input("Enter your string")
print("Your String is " + x)
if x == ("mu"):
print("game complete")
quit()
#I understand that right now I am only checking if x is mu and then
#displaying the question input
#not sure how to bring the rules into the loop too
else:
while x !=("mu"):
Question = int(input("Which rule would you like to apply? enter numbers 1-4: ")
if Question is 1:
x = (x + "l")
print(x)
elif Question is 2:
print("2")
elif Question is 3:
print("3")
elif Question is 4:
print("4")
elif Question is not 1 or 2 or 3 or 4:
print("invalid rule try again")
while
通过相应地缩进规则,将规则带入-loop:
while x != "mu":
Question = int(input("Which rule would you like to apply? enter numbers 1-4: ")
if Question == 1:
x = (x + "l")
print(x)
elif Question == 2:
print("2")
elif Question == 3:
print("3")
elif Question == 4:
print("4")
else:
print("invalid rule try again")
顺便说一句:我们is
不要比较数字。您的最后一个条件elif
是错误的,应该Question not in (1, 2, 3, 4)
甚至是简单的方法else
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句