单位转换

- 根据输入内容自由判断

- 温度

- 长度

- 货币

学习要点

- 字符串 ,数字转换

- 字典当作菜单

- print格式化

- 初步了解for 和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°