Python语言_格式符号

格式符号转换
%s字符串
%d有符号的十进制整数(正整数+负整数)
%f浮点数
%c字符
%u无符号十进制整数(正整数)
%o八进制整数
%x十六进制整数(小写ox)
%X十六进制整数(大写OX)
%e科学计数法(小写‘e’)
%E科学计数法(大写’E’)
%g%f和%e的简写
%G%f和%E的简写

以上为学习笔记,仅供学习交流。
学习网址为2019年python从入门到精通【19天全】P22

以下是一个简单的货币转换程序的 Python 代码,可以将美元、欧元和人民币相互转换。 ```python def USD_to_EUR(amount): return amount * 0.82 def EUR_to_USD(amount): return amount * 1.22 def USD_to_CNY(amount): return amount * 6.47 def CNY_to_USD(amount): return amount * 0.15 def EUR_to_CNY(amount): return amount * 7.89 def CNY_to_EUR(amount): return amount * 0.13 print("请选择转换类型:") print("1. 美元 -> 欧元") print("2. 欧元 -> 美元") print("3. 美元 -> 人民币") print("4. 人民币 -> 美元") print("5. 欧元 -> 人民币") print("6. 人民币 -> 欧元") choice = int(input("请选择转换类型(输入数字1-6):")) if choice == 1: amount = float(input("请输入美元金额:")) print("转换结果为:", round(USD_to_EUR(amount), 2), "欧元") elif choice == 2: amount = float(input("请输入欧元金额:")) print("转换结果为:", round(EUR_to_USD(amount), 2), "美元") elif choice == 3: amount = float(input("请输入美元金额:")) print("转换结果为:", round(USD_to_CNY(amount), 2), "人民币") elif choice == 4: amount = float(input("请输入人民币金额:")) print("转换结果为:", round(CNY_to_USD(amount), 2), "美元") elif choice == 5: amount = float(input("请输入欧元金额:")) print("转换结果为:", round(EUR_to_CNY(amount), 2), "人民币") elif choice == 6: amount = float(input("请输入人民币金额:")) print("转换结果为:", round(CNY_to_EUR(amount), 2), "欧元") else: print("非法输入") ``` 该程序提供了六种不同的货币转换类型,用户可以根据需要选择。用户需要输入要转换的货币金额,程序会自动计算出转换结果并显示给用户。注意,此代码仅提供基本的货币转换,如果需要更复杂的功能,需要使用更高级的 API 或库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值