1 回答
TA贡献1943条经验 获得超7个赞
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 关注
- 98 浏览
添加回答
举报