Unit conversion applet

unit conversion

- Free judgment based on input content

- temperature

- length

- currency

learning points

- string, number conversion

- Dictionary as menu

- print format

- A preliminary understanding of for and if

s = '1F'
s.strip('F')
'1'
print('欢迎使用万能单位转换器'.center(30,'*'))
menu = {'T':'温度转换','L':'长度转换','C':'货币转换'}
for k,v in menu.items():
    print(k,v)
choose = input('请输入转换类型:')
if choose == 'T':
    temp = input('请输入温度:')
    # Tf = (9/5) * Tc + 32
    temp = temp.strip('T').strip('C')
    Tf = (9 / 5) * float(temp) +32
    print(f'{Tf} = (9 / 5) * {temp} +32')
else:
    print('开发中。。。')
*********欢迎使用万能单位转换器**********
T 温度转换
L 长度转换
C 货币转换
请输入转换类型:T
请输入温度:10T
50.0 = (9 / 5) * 10 +32
print('欢迎使用万能单位转换器'.center(30,'*'))
menu = {'T':'温度转换','L':'长度转换','C':'货币转换'}
for k,v in menu.items():
    print(k,v)
choose = input('请输入转换数值(数值+单位,如1C):')
choose = choose.upper()
if choose.endswith('T'):
    choose = choose.strip('T')
    choose = float(choose)
    Tf = (9 / 5) * choose + 32 # 与浮点数运算必须是浮点数类型
    print(f'{Tf} = (9 / 5) * {choose} + 32')
elif choose.endswith('C'):
    # Tc = (5 /9) * (Tf - 32)
    choose = choose.strip('C')
    Tc = (5 / 9) * (float(choose) - 32)
    print(f'{Tc} = (5 / 9) * ({choose} -32)')
    print(f'最终结果是:{Tc}°')
else:
    print('开发中。。。')
*********欢迎使用万能单位转换器**********
T 温度转换
L 长度转换
C 货币转换
请输入转换数值(数值+单位,如1C):10c
-12.222222222222223 = (5 / 9) * (10 -32)
最终结果是:-12.222222222222223°

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324883513&siteId=291194637