Python函数,,Python中用函数


Python中用函数计算汇率;def convert_currency(im,er): out=im*er return outUSD_VS_RMB=6.77#带单位的货币输入currency_str_value=input(‘请输入带单位的货币金额:‘)unit=currency_str_value[-3:]if unit==‘CNY‘: exchange_rate=1/USD_VS_RMBelif unit==‘USD‘: exchange_rate=USD_VS_RMBelse: exchange_rate=-1if exchange_rate!=-1: in_money=currency_str_value[:-3] #调用函数 out_money=convert_currency(in_money,exchange_rate) print(‘转换后的金额:‘,out_money)else: print(‘不支持该种货币!‘)

Python函数

评论关闭