1. 程式人生 > 其它 >20212222 2021-2022-2 《Python程式設計》實驗二報告

20212222 2021-2022-2 《Python程式設計》實驗二報告

實驗二 計算器設計

# 20212222 2021-2022-2 《Python程式設計》實驗二報告

課程:《Python程式設計》
班級: 2122
姓名: 黃凱琳
學號:20212222
實驗教師:王志強
實驗日期:2022年4月4日
必修/選修: 公選課

1.實驗內容
設計二目計算器,包括整數運算與複數運算

2. 實驗過程及結果

#設定提示語

 

 #開始迴圈

設定flag 在迴圈中輸入0表示希望退出程式,

記得給result賦初值哦

 

 #使用判斷語句來選擇進行的運算操作

整體用了一個if的巢狀語句,因為是兩次判斷

1.使用普用還是複數計算器

2.進行什麼運算操作

 

 #引入複數運算

 

 #進行運算

 

 

 

3. 實驗過程中遇到的問題和解決過程

 

#flag的位置難以確定

 

 

 

 

#引入輸入複數的函式

 

 

 

 

 #不知道怎麼輸入複數

 

 

 

#程式碼

 

print("besti計算器!!!!!python好難!!!")
flag=True
while flag==True:
choice=input("請選擇你想要的計算器型別:0為普用計算器,1為複數計算器:")
if choice=="0":
op = input("請輸入需要做的操作(+/-/*// 輸入零代表退出):\n")
if op == 0:
flag = false
a = int(input("請輸入運算元1"))
b = int(input("請輸入運算元2:"))
if op == "+":
result = a + b
elif op == "-":
result = 0
result = a - b
elif op == "*":
result = a * b
elif op == "/":
result = a / b
# elif op==0:
# flag=false
else:
print("輸入有誤,請重新輸入")
contine
print("a" + op + "b=", result)
elif choice=="1":
op=input("請輸入需要的操作")
if op=="0":
break
complex1=complex(input("請輸入第一個數\n"))
complex2=complex(input("請輸入第二個數\n"))
result=0
if op == "+":
result = complex1 + complex2
elif op == "-":
result = 0
result = comple1x - complex2
elif op == "*":
result = complex1 * complex2
elif op == "/":
result = complex1 / complex2
else:
print("輸入有誤,請重新輸入")
contine
print("complex1" + op + "complex2=", result)