酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

一. 顧客在某店舖購買了12100元和3500元的東西,設計程式讓店員能夠輸入購買金額計算折扣,若金額在10000以上就打八折,金額在10000-5000以上打八五折,金額在5000-3000以上打九折,低於3000不打折,使用if-elif-else語句 二. 利用 for 迴圈把列表[1,3,5,7,9]加總,編寫一個程式,求數值的和。 三. 列表推导式中寫出[1,2,3,4,5]列表中的每位數的平方數

以下是为您提供的三个问题的 Python 代码解决方案: 问题一: ```python amount = float(input("请输入购买金额: ")) if amount > 10000: discount = amount * 0.8 elif 5000 <= amount <= 10000: discount = amount * 0.85 elif 3000 <= amount < 5000: discount = amount * 0.9 else: discount = amount print("折扣后的金额为:", discount) ``` 问题二: ```python numbers = [1, 3, 5, 7, 9] total = 0 for num in numbers: total += num print("总和为:", total) ``` 问题三: ```python numbers = [1, 2, 3, 4, 5] square_numbers = [num 2 for num in numbers] print(square_numbers) ``` [2024-10-28 14:46:54 | AI写代码神器 | 235点数解答]

相关提问