-
Notifications
You must be signed in to change notification settings - Fork 12
/
example-2.py
114 lines (95 loc) · 2.12 KB
/
example-2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Script Name : example-2.py
# Author : gaoyaqiu(球哥)
# Created : 2017-03-04
# Description : No.2 python控制流与小实例
# 2.1 python中有3种基本的控制流
# 1、顺序结构
# 2、条件分支结构
# 3、循环结构
# 条件分支结构 - if 语句
'''
a = 100
b = 10
if(a > 90):
print(a)
if(b < 90):
print(b)
elif(a > 90 and a <= 190):
print("a > 90 and a <= 190")
elif(a < 90):
print("a < 90")
else:
print("ok")
'''
# 循环结构语句 - while 语句
'''
i = 0
while(i < 5):
print("hello python")
i += 1
'''
# 循环结构语句 - for 语句, 遍历列表
'''
a = ["a1", "a2", "a3", "a4"]
for b in a:
print(b)
'''
# for 进行常规循环
'''
for i in range(0, 5):
print("hello world!")
'''
# 2.2 中断结构
# 指的是中途退出的一种结构, 常有break语句与continue语句
# break 全部退出
'''
a = ["a1", "a2", "a3", "a4"]
for i in a:
# 当i等于 a2 退出循环
if(i == "a2"):
break
print(i)
'''
# continue 中断一次循环,继续下一次循环
'''
a = ["a1", "a2", "a3", "a4"]
for i in a:
# 当i等于 a2时, 中断这次循环进入下一次循环
if (i == "a2"):
continue
print(i)
'''
# 输出乘法口诀
'''
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
4*1=4 4*2=8 4*3=12 4*4=16
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
'''
'''
for i in range(1, 10):
for j in range(1, i+1):
print(str(i) + "*" + str(j) + "=" + str(i*j), end=" ")
print()
'''
# 输出逆向乘法口诀表
'''
9*9=81 9*8=72 9*7=63 9*6=54 9*5=45 9*4=36 9*3=27 9*2=18 9*1=9
8*8=64 8*7=56 8*6=48 8*5=40 8*4=32 8*3=24 8*2=16 8*1=8
7*7=49 7*6=42 7*5=35 7*4=28 7*3=21 7*2=14 7*1=7
6*6=36 6*5=30 6*4=24 6*3=18 6*2=12 6*1=6
5*5=25 5*4=20 5*3=15 5*2=10 5*1=5
4*4=16 4*3=12 4*2=8 4*1=4
3*3=9 3*2=6 3*1=3
2*2=4 2*1=2
1*1=1
'''
for i in range(9, 0, -1):
for j in range(i, 0, -1):
print(str(i) + "*" + str(j) + "=" + str(i*j), end=" ")
print()