我是Python的新手。我写了这个,当我在输入中输入字母时出现了这个错误:
TypeError: unorderable types: str() >= int()
Run Code Online (Sandbox Code Playgroud)
这是我编写的代码:
user_input = input('How old are you?: ')
if user_input >= 18:
print('You are an adult')
elif user_input < 18:
print('You are quite young')
elif user_input == str():
print ('That is not a number')
Run Code Online (Sandbox Code Playgroud) 我做了这个简短的问卷调查:
from random import randint
def pancakes():
q = raw_input("Do you like pancakes?")
if q == "yes":
print("Great!")
elif q == "no":
print("Hmmm...")
def french_toast():
q = raw_input("Do you like french toast?")
if q == "yes":
print("Oh!")
elif q == "no":
print("Same here!")
def random():
num = 2
while num > 0:
random = randint(1, 2)
if random == 1:
num = num -1
pancakes()
elif random == 2:
num = num -1
french_toast()
random()
Run Code Online (Sandbox Code Playgroud)
我的目标是以随机顺序提出问题.但有时同样的问题会被问到两次,因为它是随机选择的.
那么我怎么能让它只问一次相同的问题呢?