commit 218188d6fdb726b8ff7faeb679aa7a2483c881a1 Author: iLoveElysia Date: Tue Sep 23 21:47:53 2025 +0000 添加 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..1a59dd3 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +好的!下面给你**标准答案**和**最终可运行程序**。 + +# PART 1:选择题答案 + +1. a +2. c +3. d +4. b +5. d +6. d + +--- + +# PART 2:编程 + +## 1) 游乐园身高/年龄判定(最终程序) + +```python +# Amusement park eligibility checker +age = int(input("Enter your age: ")) + +if age >= 9: + height = float(input("Enter your height in cm: ")) + if height > 130: + print("You may go on this ride!") + else: + print("You are too short for this ride.") +else: + print("You are too young for this ride.") +``` + +## 2) 找错并修正(4处错误已修) + +原代码中的问题: + +* `=>` 应为 `>=`(语法错误) +* `else if` 应为 `elif`(语法错误) +* 将整数与字符串比较:`userScore > "600"` 应与整数比较(类型错误) +* 打印时建议规范金额格式(逻辑/输出规范改进) + +修正后的完整代码: + +```python +IDEAL_CREDIT_SCORE = 720 + +userScore = int(input("Please enter your credit score: ")) +housePrice = float(input("Please enter the price of the house: ")) + +if userScore >= IDEAL_CREDIT_SCORE: + downPayment = 0.10 * housePrice +elif userScore < IDEAL_CREDIT_SCORE and userScore > 600: + downPayment = 0.20 * housePrice +else: + downPayment = 0.30 * housePrice + +print("Your down payment is: ${:.2f}".format(downPayment)) +``` + +需要的话我也可以给你一些快速测试用例,帮你验证输出是否符合预期。