編寫函數,實現攝氏溫度和華氏溫度的相互裝換。
公式:C*1.8+32=F
def fun():
a=int(input("請選擇:1.攝氏度轉華氏度,2.華氏度轉攝氏度:"))
if a == 1:
t = float(input("請輸入攝氏度:"))
b = t * 1.8 + 32
print("華氏度:", b)
return b
elif a == 2:
t = float(input("請輸入華氏度:"))
c = (t - 32) / 1.8
print("攝氏度:", c)
return c
fun()