华摄氏度转换

while True:

    a = input("摄氏转华氏请按1\n华氏转设施请按2\n")
    if a == '1':
        celsius = float(input('输入摄氏温度'))
        fahrenheit = (celsius * 1.8) + 32
        print('{:.2f}摄氏温度转为华氏温度为{:.2f}'.format(celsius, fahrenheit))
    elif a == '2':
        fahrenheit = float(input('输入华氏温度'))
        celsius = (fahrenheit - 32) / 1.8
        print('{:.2f}摄氏温度转为华氏温度为{:.2f}'.format(celsius, fahrenheit))
    else:
        break
华氏转设施请按2
1
输入摄氏温度100
100.00摄氏温度转为华氏温度为212.00
摄氏转华氏请按1
华氏转设施请按2
2
输入华氏温度100
37.78摄氏温度转为华氏温度为100.00
摄氏转华氏请按1
华氏转设施请按2

 

posted on 2018-09-13 09:24  095邓俊威  阅读(256)  评论(0编辑  收藏  举报