import random
print('hello')
question1 = [' cbca', ' cbbca']
print("What's equal to" + random.choice(question1) + "?")
r = input()
if r in ('7,8', '7.8', '78') and question1 == ' cbca' :
print("That's correct!")
elif r in ('1', '1,0') and str(question1) == ' cbbca' :
print("That's correct!")
else :
print('r')
无论输入是什么,都始终使用else语句。为什么?
我知道这不会那么难,但我刚刚开始这个:)
答案 0 :(得分:0)
你应该这样做:
if(r in('7,8','7.8','78'))和(question1 =='cbca'):
答案 1 :(得分:0)
您将question1
声明为列表。在其上应用random.choice
不会更改其值,因此以后它仍然是一个列表。将random.choice
的结果放在变量中并比较此变量。
import random
print('hello')
question1 = [' cbca', ' cbbca']
question = random.choice(question1) # Remember the choice of random
print("What's equal to" + question + "?")
r = input()
if r in ('7,8', '7.8', '78') and question == ' cbca' :
print("That's correct!")
elif r in ('1', '1,0') and question == ' cbbca' :
print("That's correct!")
else :
print('r')