python实现货币的转换_案例:python实现单位转换

import re

content = {‘T‘:‘温度转换‘,

‘L‘:‘长度转换‘,

‘D‘:‘货币转换‘

}

for k,v in content.items():

print(k,v)

switch_type = input(‘请输入转换类型:‘)

if switch_type == ‘T‘:

temp = input(‘请输入温度(示例:1C或者1F):‘)

if re.search(‘C‘,temp):

temp = float(temp.strip(‘C‘))

Tf = (9/5)*temp + 32

print(f‘F=9/5*{temp}+32={Tf}F‘)

elif re.search(‘F‘,temp):

temp = float(temp.strip(‘F‘))

Tc = (5/9)*(temp - 32)

print(f‘C=5/9*({temp}-32)={Tc}C‘)

else:

print(‘输入有误,示例:1C或者1F‘)

if switch_type == ‘L‘:

temp = input(‘请输入长度(示例:1m或者1ft):‘)

if re.search(‘m‘,temp):

temp = float(temp.strip(‘m‘))

ft = 3.281*temp

print(f‘ft=3.281*{temp}={ft}ft‘)

elif re.search(‘ft‘,temp):

temp = float(temp.strip(‘ft‘))

M = 0.3048*temp

print(f‘M=3.281*{temp}={M}m‘)

else:

print(‘输入有误,示例:1m或者1ft‘)

if switch_type == ‘D‘:

temp = input(‘请输入货币(示例:1美元或者1人民币元):‘)

if re.search(‘美元‘,temp):

temp = float(temp.strip(‘美元‘))

RMB = 6.671*temp

print(f‘RMB=6.671*{temp}={RMB}人民币元‘)

elif re.search(‘人民币元‘,temp):

temp = float(temp.strip(‘人民币元‘))

dollar = 0.1499*temp

print(f‘dollar=0.1499*{temp}={dollar}美元‘)

else:

print(‘输入有误,示例:1美元或者1人民币元‘)

T 温度转换

L 长度转换

D 货币转换

请输入转换类型:T

请输入温度(示例:1C或者1F):10C

F=9/5*10.0+32=50.0F

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值