ITeye博客

Python if elif else

fairy_xzc · 2016-09-28 13:21 · Python · 编程语言 · Markdown

原创转载请注明出处: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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。