如何使python接受随机输入

如何使python接受随机输入,python,python-2.7,input,Python,Python 2.7,Input,我目前正在从事一个python项目,我需要它在某个时候接受用户的随机输入 因此,如果我有,例如: def question_one () : answer_one = raw_input ('How many days are there in a week? ').lower() try: if answer_one == 'seven' or answer_one == '7' : question_2() 凡事都能创造奇迹。但是如

我目前正在从事一个python项目,我需要它在某个时候接受用户的随机输入

因此,如果我有,例如:

def question_one () :
    answer_one = raw_input ('How many days are there in a week? ').lower()
    try: 
        if answer_one == 'seven' or answer_one == '7' :
            question_2()
凡事都能创造奇迹。但是如何让python接受随机输入,如中所示

def question_two () :
    answer_two = raw_input ('What´s your mother´s name? ').lower()
    try: 
        if answer_two == ***I have no idea how to code this part*** :
            question_3()

在这种情况下,我需要python来接受任何输入,并且仍然让用户进入下一个问题。我该怎么做呢?

如果输入不必是特定的形式,或者没有特定的属性,那么就不需要If语句,甚至不需要try


只需删除if子句即可

如果你想重新问这个问题,如果他们没有答对,你可以像这样回过头来问。这个问题唯一可以接受的答案是“是”,或者“是”,等等。。 如果他们回答不正确,它会再次询问他们,直到他们答对为止

def question1():
    answer1 = raw_input("Do you like chickens?")
    answer1 = answer1.lower()
    if answer1 == 'yes':
        print "That is Correct!"
        question2()
    else:
        question1()
如果你想让他们即使错了也能继续下一个问题,你可以这样做:

def question1():
    answer1 = raw_input("Do you like chickens?")
    answer1 = answer1.lower()
    if answer1 == 'yes':
        print "That is Correct!"
    else:
        print "Next question coming!"
    question2()

def question2():
    answer2 = raw_input("How many days in a week?")
    answer2 = answer2.lower()
    if answer2 == '7' or answer2 == "seven":
        print "That is Correct!"
    else:
        print "Sorry,that was wrong"
    question3()

在第二个示例中,为if…else子句的两个分支调用question2很容易出错。把它搬到外面去,谢谢!是的,那是我的问题。
def question1():
    answer1 = raw_input("Do you like chickens?")
    answer1 = answer1.lower()
    if answer1 == 'yes':
        print "That is Correct!"
    else:
        print "Next question coming!"
    question2()

def question2():
    answer2 = raw_input("How many days in a week?")
    answer2 = answer2.lower()
    if answer2 == '7' or answer2 == "seven":
        print "That is Correct!"
    else:
        print "Sorry,that was wrong"
    question3()