Skip to content

Commit

Permalink
homework for 2nd class
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHahaha committed Jul 5, 2018
1 parent ff038ec commit d0e14f4
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Practice2-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 四則運算

while True :

print('\n這是小學生計算機, 運算式請輸入 "+,-,*,/" \n')
print("輸入格式 : 3 * 5 (全部輸入完請按 Enter ) \n")
try:
n1,op,n2=input().split()
except ValueError:
print("\n忘記空格了齁! 重來 OK ?!\n")
continue



n1=int(n1)
n2=int(n2)


print("= ",end="")


if op =="+":
print(n1+n2)


elif op =="-":
print(n1-n2)


elif op =="*":
print(n1*n2)


elif op =="/":
print(n1/n2)


else :
print("What the hell ?")

print("\n")




33 changes: 33 additions & 0 deletions Practice2-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 使用者輸入一個正整數,算整數平方根

while True:

print("\n我要來算平方根, you know.")
n=int(input("請輸入一個正整數 : "))
x=1

while x**2 <= n:

if x**2 == n:
print("\n",n,"的平方根 = " ,x)
break

else :
x+=1
if x**2>n :
print("\nSorry 我只有國中智商...")
print("輸入個我會算的 QAQ\n")
continue

else:
w=input("\n還要再看我表演一次嗎? y or n :")

if w=="y" :

continue

else:
print("\nBye !")

break

42 changes: 42 additions & 0 deletions Practice2-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 輸出九九乘法表

print("Ladies & Gentleman !")
print("來看我一次變出九九乘法表囉!")
print("倒數五秒~\n")

import threading
import time

def fun_timer():

print("秒")
global timer
timer = threading.Timer(1, fun_timer)
timer.start()

print("秒")

timer = threading.Timer(1, fun_timer)
timer.start()

time.sleep(5)
timer.cancel()


for w in range(1,10) :

for n in range(1,9):

if n*w <10 :
print(n,"x",w,"= ",n*w,end=" ")

else:
print(n,"x",w,"=",n*w,end=" ")

if w==1:
print(9,"x",w,"= ",9*w)
else:
print(9,"x",w,"=",9*w)



23 changes: 23 additions & 0 deletions Practice2-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 質數偵測

print("\n我要來幫你檢查是不是質數了, you know.")
n=int(input("請輸入一個正整數 : "))
print("\n",n,"的因數有 : ",end="")
const=0

for x in range(1,n+1) :

if n%x ==0 :

print(x,",",end=" ")
const+=1


if const >=3 :

print("\n\n除了 1 和",n,"以外還有其他因數")
print("\n所以",n,"不是質數 ~")

else:
print("\n\n唉呦, 看來",n,"是質數喔 ~")

0 comments on commit d0e14f4

Please sign in to comment.