这就是我想要做的:
age = input("What is your age?")
if age in range (18,30):
print("You are young")
else:
print("You are old")
这是怎么了?我该如何正确地执行此范围操作?
答案 0 :(得分:0)
正如Devesh所说,您需要使用int(age)
将age转换为整数。此外,range
和(18,30)
之间不应有空格。
将其更改为:
age = int(input("What is your age?"))
if age in range(18,30):
print("You are young")
else:
print("You are old")