If statement 如何编写具有间隔的if语句?
我想不出来。 到目前为止,我有,但它不工作,无论我输入什么年龄,它告诉我我可以成为总统If statement 如何编写具有间隔的if语句?,if-statement,intervals,python-3.4,If Statement,Intervals,Python 3.4,我想不出来。 到目前为止,我有,但它不工作,无论我输入什么年龄,它告诉我我可以成为总统 import math (x) = input("Please enter your name:") (y) = input("Please enter your age:") print ("Hello" + x) print ("Your age is" + y) if ("y")> ("0") and ("y") < ("18"): print("You are a min
import math
(x) = input("Please enter your name:")
(y) = input("Please enter your age:")
print ("Hello" + x)
print ("Your age is" + y)
if ("y")> ("0") and ("y") < ("18"):
print("You are a minor.")
if ("y")>=("18") and ("y") < ("25"):
print("You can vote.")
if ("y")>= ("25") and ("y") < ("35"):
print("You can rent a car.")
if ("y") >= ("35"):
print("You can be president.")
else:
print ("You have not entered a valid response. Must be a positive integer.")
如何正确地获得间隔?在Python中编写不等式范围比执行不同的截断要简单得多;可以使用数学样式范围 下面是一个例子:
if 0 < y < 18:
print("You are a minor.")
您不应该引用变量,因为这样会将其视为字符串文字。在awesome Makoto的帮助下,它已修复!:D 输入数学 x=输入请输入您的姓名: y=IntInput请输入您的年龄: 打印Hello+x 打印你的年龄是,y 如果0
elif 18括号中的东西应该是变量吗?你不想要元组,是吗?我会去掉括号,因为这只会给您带来混乱。如果我这样做,我会得到以下错误:回溯最近的调用last:文件C:\Python34\Age3.py,第11行,在If 0