Skip to content

Commit

Permalink
homework for the 3rd class
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHahaha committed Jul 21, 2018
1 parent 6a5e9bf commit 5b4cb8e
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 0 deletions.
Empty file added Prac3/__init__.py
Empty file.
Binary file added Prac3/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added Prac3/__pycache__/calculate.cpython-36.pyc
Binary file not shown.
Binary file added Prac3/__pycache__/multiple.cpython-36.pyc
Binary file not shown.
26 changes: 26 additions & 0 deletions Prac3/calculate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@



def Cal(n1,n2,op) :


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")
22 changes: 22 additions & 0 deletions Prac3/multiple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

def list(n1,n2) :

for w in range(n1,n2+1) :

for n in range(n1,n2):

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

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

if w==1 and n2==9 :

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

print(n2,"x",w,"= ",n2*w)

return

59 changes: 59 additions & 0 deletions Practice3-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 程式包裝
# 1. 把 99 乘法表包裝成函式,可做 n1xn2 乘法
# 2. 把四則運算機包裝成函式
# 3. 將以上函式包裝在自己的模組和封包中,並且在主程式成功使用

import Prac3.multiple as m
import Prac3.calculate as c

while True:

print("\n1. 四則運算機\n2. n1 x n2 乘法表 \n")
choice=input("輸入 1 或 2 選擇你要執行的項目 : ")

if choice=="1" :

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="")

c.Cal(n1,n2,op)
break

elif choice=="2" :
x=int(input("\nEnter n1 : "))
y=int(input("Enter n2 : "))

if x<y:
print("\n")
m.list(x,y)
print("\n")
elif x>y:
print("\n")
m.list(y,x)
print("\n")
else:
print("\n",x,"x",y,"=",x*y,"\n")

else:
print("\n賣鬧 ! \n")
continue

ans=input("Do You Wanna Play Again ? (y/n) : ")

if ans=="Y" or ans=="y" :
print("\n")
continue
else :
print("\nBye !")
break
19 changes: 19 additions & 0 deletions Practice3-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 從官網資訊學習使用系統內建的模組 random 產生 1~100 間的亂數


import random

# n = random.randint(1,100)

# 呈現 1~100 10x10 亂數矩陣

x=random.sample(range(1,101),k=100)
a=1
while a<=100:
if a%10==0:
print(x[a-1])
a+=1
else:
print(x[a-1],end="\t")
a+=1

0 comments on commit 5b4cb8e

Please sign in to comment.