用python某商店T恤的价格为35元/件(2件9折,3件以上9折),裤子的价格为120 元/条(2条以上9折).(例如:小明在该店买了3件T恤和2条裤子,请计算并显示小明应该付多少钱?)
时间: 2024-03-25 13:39:43 浏览: 15
好的,根据您提供的信息,我可以写一个Python程序来计算小明应该支付的金额。以下是程序代码:
```python
num_tshirt = 3 # T恤数量
num_pants = 2 # 裤子数量
price_tshirt = 35 # T恤单价
price_pants = 120 # 裤子单价
if num_tshirt < 2:
total_tshirt = num_tshirt * price_tshirt
elif num_tshirt >= 2 and num_tshirt < 3:
total_tshirt = num_tshirt * price_tshirt * 0.9
else:
total_tshirt = num_tshirt * price_tshirt * 0.9 * 0.9
if num_pants < 2:
total_pants = num_pants * price_pants
else:
total_pants = num_pants * price_pants * 0.9
total = total_tshirt + total_pants
print("小明应该支付的金额为:", total, "元")
```
根据您提供的数据,程序将输出小明应该支付的金额为:`547.5` 元。
相关问题
python某商店出售品牌服装,每件定价150,1件不打折,2件以及3件都打九折,买4件到9件打八折,买10件以上打七折,键盘输入购买数量,屏幕输出总额(保留整数)
好的,这是一个简单的 Python 程序,可以实现您的需求:
```python
num = int(input("请输入购买数量:"))
price = 150 # 每件定价150元
if num == 1:
total_price = price
elif num == 2 or num == 3:
total_price = int(num * price * 0.9)
elif num >= 4 and num <= 9:
total_price = int(num * price * 0.8)
else:
total_price = int(num * price * 0.7)
print("总价为:", total_price, "元")
```
解释一下程序的思路:
1. 首先通过 `input` 函数获取用户输入的购买数量,使用 `int()` 函数将输入的字符串转换为整数类型存储在 `num` 变量中。
2. 然后根据购买数量的不同,使用不同的打折方案计算总价,并将结果存储在 `total_price` 变量中。
3. 最后使用 `print` 函数输出结果。
希望这个程序能帮助到您!
python某商店出售某品牌服装,没见定价160,1件不打折,2件到3件打九折,4件到9件打八折,10件以上打七折,键盘输入购买数量,屏幕输出总额(保留整数)
好的,这是一个简单的Python程序,你可以直接复制粘贴运行:
```python
num = int(input("请输入购买数量: "))
price = 160
total_price = 0
if num == 1:
total_price = price
elif num >= 2 and num <= 3:
total_price = int(price * num * 0.9)
elif num >= 4 and num <= 9:
total_price = int(price * num * 0.8)
else:
total_price = int(price * num * 0.7)
print("总额是:", total_price)
```
你只需要输入购买数量,程序会自动计算总额并输出。注意,程序中的价格为160,如有变动请自行修改。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)