以攝氏度為單位給出溫度。任務是轉換華氏刻度中的值並顯示它。
例子:
Input: 37 Output: 37.00 Celsius is:98.60 Fahrenheit Input: 40 Output: 40.00 Celsius is equivalent to:104.00 Fahrenheit
方法:
取攝氏溫度作為用戶輸入,應用華氏溫度與攝氏溫度的換算公式,並顯示出來。攝氏度和華氏度之間的關係由下式給出:
下麵是實現。
Python3
# Temperature in celsius degree
celsius = 40
# Converting the temperature to
# fehrenheit using the above
# mentioned formula
fahrenheit = (celsius * 1.8) + 32
# printing the result
print('%.2f Celsius is equivalent to:%.2f Fahrenheit'
%(celsius, fahrenheit))
輸出:
40.00 Celsius is equivalent to:104.00 Fahrenheit
相關用法
注:本文由純淨天空篩選整理自devanshigupta1304大神的英文原創作品 Python Program to Convert Celsius To Fahrenheit。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。