Skip to content

Commit d0e14f4

Browse files
committed
homework for 2nd class
1 parent ff038ec commit d0e14f4

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

Practice2-1.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# 四則運算
2+
3+
while True :
4+
5+
print('\n這是小學生計算機, 運算式請輸入 "+,-,*,/" \n')
6+
print("輸入格式 : 3 * 5 (全部輸入完請按 Enter ) \n")
7+
try:
8+
n1,op,n2=input().split()
9+
except ValueError:
10+
print("\n忘記空格了齁! 重來 OK ?!\n")
11+
continue
12+
13+
14+
15+
n1=int(n1)
16+
n2=int(n2)
17+
18+
19+
print("= ",end="")
20+
21+
22+
if op =="+":
23+
print(n1+n2)
24+
25+
26+
elif op =="-":
27+
print(n1-n2)
28+
29+
30+
elif op =="*":
31+
print(n1*n2)
32+
33+
34+
elif op =="/":
35+
print(n1/n2)
36+
37+
38+
else :
39+
print("What the hell ?")
40+
41+
print("\n")
42+
43+
44+
45+

Practice2-2.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 使用者輸入一個正整數,算整數平方根
2+
3+
while True:
4+
5+
print("\n我要來算平方根, you know.")
6+
n=int(input("請輸入一個正整數 : "))
7+
x=1
8+
9+
while x**2 <= n:
10+
11+
if x**2 == n:
12+
print("\n",n,"的平方根 = " ,x)
13+
break
14+
15+
else :
16+
x+=1
17+
if x**2>n :
18+
print("\nSorry 我只有國中智商...")
19+
print("輸入個我會算的 QAQ\n")
20+
continue
21+
22+
else:
23+
w=input("\n還要再看我表演一次嗎? y or n :")
24+
25+
if w=="y" :
26+
27+
continue
28+
29+
else:
30+
print("\nBye !")
31+
32+
break
33+

Practice2-3.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# 輸出九九乘法表
2+
3+
print("Ladies & Gentleman !")
4+
print("來看我一次變出九九乘法表囉!")
5+
print("倒數五秒~\n")
6+
7+
import threading
8+
import time
9+
10+
def fun_timer():
11+
12+
print("秒")
13+
global timer
14+
timer = threading.Timer(1, fun_timer)
15+
timer.start()
16+
17+
print("秒")
18+
19+
timer = threading.Timer(1, fun_timer)
20+
timer.start()
21+
22+
time.sleep(5)
23+
timer.cancel()
24+
25+
26+
for w in range(1,10) :
27+
28+
for n in range(1,9):
29+
30+
if n*w <10 :
31+
print(n,"x",w,"= ",n*w,end=" ")
32+
33+
else:
34+
print(n,"x",w,"=",n*w,end=" ")
35+
36+
if w==1:
37+
print(9,"x",w,"= ",9*w)
38+
else:
39+
print(9,"x",w,"=",9*w)
40+
41+
42+

Practice2-4.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 質數偵測
2+
3+
print("\n我要來幫你檢查是不是質數了, you know.")
4+
n=int(input("請輸入一個正整數 : "))
5+
print("\n",n,"的因數有 : ",end="")
6+
const=0
7+
8+
for x in range(1,n+1) :
9+
10+
if n%x ==0 :
11+
12+
print(x,",",end=" ")
13+
const+=1
14+
15+
16+
if const >=3 :
17+
18+
print("\n\n除了 1 和",n,"以外還有其他因數")
19+
print("\n所以",n,"不是質數 ~")
20+
21+
else:
22+
print("\n\n唉呦, 看來",n,"是質數喔 ~")
23+

0 commit comments

Comments
 (0)