1 回答

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊
import time
degree_sign = u'\N{DEGREE SIGN}'
def fahrenheit():
degree = int(input('\nHow many degrees is it currently in Fahrenheit?: '))
a = round((degree - 32) * 5/9)
return a
def celsius():
degree = int(input('\nHow many dgrees is it currently in Celsius?: '))
a = round((degree * 9/5) + 32)
return a
print("Welcome to my first weather conversion!\n")
weather = input('Do you want to convert to Fahrenheit or Celsius (c/f)? \n').lower()
d = {"c": f"{fahrenheit()}{degree_sign}C",
"f": f"{celsius()}{degree_sign}F"}
if weather == "c":
time.sleep(0.5)
print(f'It is currently {fahrenheit()}{degree_sign}C.')
elif weather == "f":
time.sleep(0.5)
print(f'\nIt is currently {celsius()}{degree_sign}F.')
else:
while True:
print("\nI'm sorry I don't understand.\n")
weather = input('Do you want to convert to Fahrenheit or Celsius (c/f)? \n').lower()
try:
time.sleep(0.5)
print("It is currently ", d[weather])
except:
continue
同樣可以修改其他if-else子句
- 1 回答
- 0 關(guān)注
- 117 瀏覽
添加回答
舉報(bào)