这是我的作业,你被提供了一个人的年龄,你需要确定这个人所在的学校级别。
If 6 to 11 output ‘primary school’
If 12 to 18 output ‘secondary school’
If neither, then output ‘NA’
这是我的代码
import sys
age= int(sys.argv[1])
if age >= 6.0 and age <=11:
print ('primary school')
if age >=12 and age <=18:
print ('secondary school')
if age < 6.0 and age >18:
print ('NA')
这是我的错误程序输出
Program Failed for Input: 5
Expected Output: NA
Your Program Output:
我做错了什么?
发布于 2018-01-17 22:36:09
你需要一个or
if age < 6 or age > 18:
age
不能小于6
,不能同时大于18
。此外,通过使用if-elif-else
结构并链接不等式,可以完全避免最后一种情况:
if 6 <= age <= 11:
print('primary school')
elif 12 <= age <= 18:
print ('secondary school')
else:
print ('NA')
发布于 2018-01-17 22:40:00
年龄值不能低于6,同时高于18
if age<6 or age>18:
print ("NA")
https://stackoverflow.com/questions/48303580
复制相似问题