Python if elif else

原创转载请注明出处:http://agilestyle.iteye.com/blog/2327544

ifelse.py

age = input()
print('Your age is: ', age)

# input()返回的数据类型是str,str不能直接和整数比较,必须先把str转换成整数
# Python提供int()函数来完成这件事情
age = int(age)

# if <条件判断1>:
#     <执行1>
# elif <条件判断2>:
#     <执行2>
# elif <条件判断3>:
#     <执行3>
# else:
#     <执行4>
if age >= 18:
    print('adult')
elif age >= 6:
    print('teenager')
else:
    print('kid')

Console Output


 

猜你喜欢

转载自agilestyle.iteye.com/blog/2327544