Skip to content

Commit f9e2eb4

Browse files
committed
new stance of program
1 parent dcc96e3 commit f9e2eb4

6 files changed

Lines changed: 94 additions & 0 deletions

File tree

python3code/chapter02/aliquot.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#coding:utf-8
2+
'''
3+
filename: aliquot.py
4+
'''
5+
6+
aliquot = []
7+
8+
for n in range(1,100):
9+
if n % 3 == 0:
10+
aliquot.append(n)
11+
12+
print(aliquot)

python3code/chapter02/evenbreak.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#coding:utf-8
2+
'''
3+
filename: evenbreak.py
4+
'''
5+
6+
a = 8
7+
while a:
8+
if a%2 == 0:
9+
break
10+
else:
11+
print("{} is odd number".format(a))
12+
a -= 1
13+
print("{} is even number".format(a))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#coding:utf-8
2+
'''
3+
filename: evencontinue.py
4+
'''
5+
6+
a = 9
7+
while a:
8+
if a%2 == 0:
9+
a -=1
10+
continue #如果是偶数,就返回循环的开始
11+
else:
12+
print("{} is odd number".format(a)) #如果是奇数,就打印出来
13+
a -=1

python3code/chapter02/forelse.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding:utf-8
2+
'''
3+
filename: forelse.py
4+
'''
5+
6+
from math import sqrt
7+
8+
for n in range(99, 1, -1):
9+
root = sqrt(n)
10+
if root == int(root):
11+
print(n)
12+
break
13+
14+
else:
15+
print("Nothing.")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#coding:utf-8
2+
'''
3+
filename: guessnumber.py
4+
'''
5+
6+
import random
7+
8+
number = random.randint(1,100)
9+
10+
guess = 0
11+
12+
while True:
13+
14+
num_input = input("please input one integer that is in 1 to 100:")
15+
guess += 1
16+
17+
if not num_input.isdigit():
18+
print("Please input interger.")
19+
elif int(num_input) < 0 or int(num_input) >= 100:
20+
print("The number should be in 1 to 100.")
21+
else:
22+
if number == int(num_input):
23+
print("OK, you've done well.It is only %d, then you succeed." % guess)
24+
break
25+
elif number > int(num_input):
26+
print("your number is smaller.")
27+
elif number < int(num_input):
28+
print("your number is bigger.")
29+
else:
30+
print("There is something bad, I will not work")

python3code/chapter02/whileelse.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#coding:utf-8
2+
'''
3+
filename: whileelse.py
4+
'''
5+
6+
count = 0
7+
while count < 5:
8+
print(count, " is less than 5")
9+
count = count + 1
10+
else:
11+
print(count, " is not less than 5")

0 commit comments

Comments
 (0)