2016-04-21 27 views
-2

由于您不喜欢我对程序的解释,因此我已将其纯粹更改为只是一个问题: 如何让程序继续检查输入是什么并根据适用的规则,直到输出亩无法让我的程序继续正常进行,直到返回true

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

我不知道你在问什么。请尝试用简短的句子来写下你的问题,而不是无休止的晦涩难懂的话。 – Julien

+0

我的问题是如何让程序继续检查输入是什么,并根据输出为mu来应用规则,只是认为人们想要了解该程序 –

回答

2

您可以通过相应的缩进来使这些规则到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

+0

此代码实际上并没有运行a)在问题命令 –

+0

的末尾修正了它,并且它可以正常工作,我以为如果其他人的问题出现在其他问题中,哪一个问题是其中一个问题 –