Python学习之==>条件判断

1、单条件判断

1 # 接收输入的值,使用input函数,用input接收输入的值都是string类型的
2 age = input('请输入你的年龄:')
3 age = int(age)  # 类型转换,转换成int类型
4 if age < 18:
5    print('未成年人')
6 else:
7    print('成年人')

2、多条件判断(and)

 1 score = input('请输入你的成绩:')
 2 score = int(score)  # 类型转换,转换成int类型
 3 if score >= 90:
 4     print('优秀')
 5 elif score >= 75 and score < 90:
 6     print('良好')
 7 elif score >= 60 and score < 75:
 8     print('及格')
 9 else:
10     print('不及格')

3、多条件判断(or)

1 sex = input('请输入你的性别:')
2 if sex == '' or sex == '':
3     print('性别合法')
4 else:
5     print('性别不合法')

 

posted on 2018-04-12 15:36  破解孤独  阅读(1434)  评论(0编辑  收藏  举报

导航