1. 程式人生 > >理解數據類型與數學運算:求和、溫度轉換2

理解數據類型與數學運算:求和、溫度轉換2

pan style alt 數學運算 inpu int com img png

a = int(input(攝氏溫度轉換為華氏溫度請按 1\n華氏溫度轉換為攝氏溫度請按 2\n))
if a==1:
    c = float(input(請輸入攝氏溫度:))
    f = c*9/5+32
    print(攝氏{:.2f}的華氏為{:.2f}.format(c,f))
else:
    f = float(input(請輸入華氏溫度:))
    c = 5/9*(f-32)
    print(華氏{:.2f}的攝氏為{:.2f}.format(f,c))

技術分享圖片

理解數據類型與數學運算:求和、溫度轉換2