File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ # 打印list
2+ names = ['bob' , 'trac' , 'mich' ]
3+
4+ for name in names :
5+ print (name )
6+
7+ # 打印
8+ # bob
9+ # trac
10+ # mich
11+
12+ # 打印 0 - 9
13+
14+ for x in range (10 ):
15+ print (x )
16+
17+ #累加 0 - 9
18+ sum = 0
19+ for x in range (10 ):
20+ sum = sum + x
21+ print (sum ) #45
22+
23+ # 100 以内所有奇数和
24+ sum = 0
25+ n = 99
26+
27+ while n > 0 :
28+ sum = sum + n
29+ n = n - 2
30+ print (sum ) #2500
31+
32+ # break
33+
34+ n = 1
35+ while n <= 100 :
36+ if n > 10 : # 当n = 11时,条件满足,执行break语句
37+ break # break语句会结束当前循环
38+ print (n )
39+ n = n + 1
40+ print ('END' )
41+
42+ #continue
43+ n = 0
44+ while n < 10 :
45+ n = n + 1
46+ if n % 2 == 0 : # 如果n是偶数,执行continue语句
47+ continue # continue语句会直接继续下一轮循环,后续的print()语句不会执行
48+ print (n )
Original file line number Diff line number Diff line change 1+ #input()返回的数据类型是str,str不能直接和整数比较,必须先把str转换成整数。Python提供了int()函数来完成这件事情:
2+
3+ s = input ('birth :' )
4+ birth = int (s )
5+
6+ if birth < 2000 :
7+ print ('00前' )
8+ else :
9+ print ('00后' )
You can’t perform that action at this time.
0 commit comments