如何在python中连接这两个语句

时间:2016-07-19 11:01:18

标签: python

if ask == "yes" or ask == "Yes":
    print("lets go, if you dont know a question you can say 'I dont know' to leave the gameshow")
else:
    if ask == "no" or ask == "No":
     print("then go home")

    exit(ask)

print("What is the capital of Sarajevo?")

if ask == "sarajevo" or ask == "Sarajevo":
  print("Correct, you get to move on")
else:
    if ask == "i don't know" or ask == "I don't know":
     print("Sorry that isn't correct, you lost")
     exit(ask)

无论我尝试什么,他们都只是最终被打印

2 个答案:

答案 0 :(得分:0)

要使整个事情有意义,用户必须使用ask提供input()。所以我假设它是。以下是您的代码的修改版本。请注意,您无需正确获取案例。您可以使用lower()字符串方法将您给出的任何答案转换为小写。

ask = input('Please provide an answer..\t')
if ask.lower() == "yes":
    print("lets go, if you dont know a question you can say 'I dont know'")
    print("What is the capital of Sarajevo?")    
    ask = input('Please provide an answer..\t')
    if ask.lower() == "sarajevo":
        print("Correct, you get to move on")
    else:
        print("Sorry that isn't correct, you lost and have to leave the gameshow")
elif ask.lower() == "no":
    print("then go home")

看看它并告诉我这是否适合你。 ☺

答案 1 :(得分:0)

我不明白你要连接的是哪两个语句 检查这是否适合您:

if ask == "yes" or ask == "Yes":
    statement 1 = "lets go, if you dont know a question you can say 'I dont know' to leave the gameshow"
    print("lets go, if you dont know a question you can say 'I dont know' to leave the gameshow")
elif ask == "no" or ask == "No":
    print("then go home")
    statement 2 = "then go home"
exit(ask)

print("What is the capital of Sarajevo?")

if ask == "sarajevo" or ask == "Sarajevo":
     print("Correct, you get to move on")
     statement 3 = "Correct, you get to move on"
elif ask == "i don't know" or ask == "I don't know":
     print("Sorry that isn't correct, you lost")
     statement 4 = "Sorry that isn't correct, you lost"
 exit(ask)

statement = statement 1 + statement 3 
print statement
statement = statement 2 + statement 4
print statement