Skip to content

Commit a28633c

Browse files
committed
update if & for & while
1 parent be7f57b commit a28633c

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

.idea/PythonPracticeProject.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyleSettings.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

day3/__init__.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# if 语句
4+
print '------------- if 语句 ----------------'
5+
6+
age = 23
7+
if age >= 12:
8+
print 'I am not 12, I am only 23!'
9+
print 'haha~~'
10+
print "end"
11+
12+
# if else
13+
print '------------- if else ----------------'
14+
if not age < 20:
15+
print 'come on baby!'
16+
17+
if age >= 30:
18+
print 'I am an old man!'
19+
else:
20+
print 'I am a teenager!'
21+
22+
# if else if else
23+
print '------------- if else if else ----------------'
24+
if age >= 18:
25+
print 'adult'
26+
else:
27+
if age >= 6:
28+
print 'teenager'
29+
else:
30+
if age >= 3:
31+
print 'kid'
32+
else:
33+
print 'baby'
34+
35+
print '------------ elif --> else if -------------'
36+
if age >= 18:
37+
print 'adult'
38+
elif age >= 6:
39+
print 'teenager'
40+
elif age >= 3:
41+
print 'kid'
42+
else:
43+
print 'baby'
44+
45+
# for 循环
46+
print '------------- for 循环 ----------------'
47+
names = ['micheal', 'lincoln', 'benjamin', 'john', 'fernando', 'sucre', 'bagel']
48+
for name in names:
49+
print name
50+
51+
# while 循环
52+
print '------------- while 循环 ----------------'
53+
a = 10
54+
b = 9
55+
while a >= b:
56+
print b
57+
b = b + 1
58+
print 'a = ', a, ' b = ', b
59+
60+
# break 退出循环
61+
print '------------- break 退出循环 ----------------'
62+
63+
c = 20
64+
while b < c:
65+
print b
66+
b = b + 1
67+
if b > 15:
68+
break
69+
print 'while ---'
70+
print 'end b = ', b
71+
72+
# continue 继续循环
73+
print '------------- continue 继续循环 ----------------'
74+
75+
d = 30
76+
while b < d:
77+
b = b + 1
78+
if b < 25:
79+
continue
80+
print b
81+
print 'end b = ', b
82+
83+
# 嵌套for循环
84+
print '------------- 嵌套for循环 ----------------'
85+
86+
for x in ['A', 'B', 'C']:
87+
for y in ['1', '2', '3']:
88+
print x + y

0 commit comments

Comments
 (0)