以下是使用 Python 实现的代码: ```python while True: shopping_amount = float(input("请输入购物额:")) if shopping_amount >= 1000: payment = shopping_amount * 0.8 elif 500 <= shopping_amount < 1000: payment = shopping_amount * 0.9 elif 200 <= shopping_amount < 500: payment = shopping_amount * 0.95 elif 0 <= shopping_amount < 200: payment = shopping_amount * 0.97 else: print("输入有误,请重新输入!") continue print("应收款额为:", payment) ``` 以下是 3 个改进建议: 1. 可以添加对输入是否为数字的判断,避免输入非数字导致程序出错。 2. 可以增加异常处理机制,如捕获输入转换为浮点数时可能出现的错误。 3. 可以对代码进行函数封装,提高代码的复用性和可读性。 [2024-12-26 14:19:41 | AI写代码神器 | 241点数解答]