[Python3實例] 溫度轉換程序

#溫度轉換

print('華氏攝氏溫度轉換器')
tempstr = input("請輸入溫度 例: 23C(23攝氏度) 52F(52華氏度)\n")
if tempstr[-1] in ['C', 'c']:
    f = float(tempstr[0:-1])*1.8+32
    print('{:.2f}F'.format(f))
elif tempstr[-1] in ['F', 'f']:
    c = (float(tempstr[0:-1])-32)/1.8
    print('{:.2f}C'.format(c))
else:
    print('輸入錯誤!')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章