无法让我的程序继续正常,直到为真

时间:2016-04-21 06:10:17

标签: python loops input

既然你不喜欢我对我的程序的解释,我现在只是将它改为纯粹的问题: 如何允许程序继续检查输入是什么,并根据输出是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")

1 个答案:

答案 0 :(得分:2)

通过相应地缩进规则,将规则引入while - 循环:

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