day04控制流程之if判断

本文详细介绍了Python中if语句的使用方法,包括基本语法、条件判断、逻辑运算符的应用,以及多条件分支的处理。通过实例展示了如何利用if语句进行逻辑控制,使程序具备判断能力。

 一.控制流程之if判断

        1、什么是if判断

           判断一个条件如果成立则。。。不成立则。。。

   2、为何要有if判断

       让计算机能够像人一样具有判断能力

   3、如何用if判断

 1 '''
 2 # 语法1:
 3 '''
 4 if 条件1:
 5     code1
 6     code2
 7     code3
 8     ......
 9 '''
10 # age=18
11 # if age != 18:
12 #     print('你好啊小伙子')
13 #     print('加个微信吧...')
14 # print('other code...')
15 
16 # 语法2:
17 '''
18 if 条件:
19     code1
20     code2
21     code3
22     ......
23 else:
24     code1
25     code2
26     code3
27     ......
28 '''
29 # age=18
30 # sex='male'
31 # wuzhong='human'
32 # is_beautiful=True
33 #
34 # if age > 16 and age < 22 and sex == 'female' and \
35 #         wuzhong == 'human' and is_beautiful:
36 #     print('开始表白...')
37 # else:
38 #     print('阿姨好,我逗你玩呢...')
39 
40 
41 # 语法3:
42 '''
43 if 条件1:
44     if 条件2:
45         code1
46         code2
47         code3
48     code2
49     code3
50     ......
51 '''
52 # age = 18
53 # sex = 'female'
54 # wuzhong = 'human'
55 # is_beautiful = True
56 # is_successful = True
57 #
58 # if age > 16 and age < 22 and sex == 'female' and wuzhong == 'human' and is_beautiful:
59 #     print('开始表白...')
60 #     if is_successful:
61 #         print('在一起')
62 #     else:
63 #         print('阿姨再见....')
64 # else:
65 #     print('阿姨好,我逗你玩呢...')
66 
67 # 语法4:
68 '''
69 if 条件1:
70     子代码块1
71 elif 条件2:
72     子代码块2
73 elif 条件3:
74     子代码块3
75 elif 条件4:
76     子代码块4
77 .........
78 else:
79     子代码块5
80 '''
81 
82 score = input('your score>>: ')
83 score=int(score)
84 if score >= 90:
85     print('优秀')
86 elif score >= 80:
87     print('良好')
88 elif score >= 70:
89     print('普通')
90 else:
91     print('很差')

 

转载于:https://www.cnblogs.com/frank007/p/9647184.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值