2025-09-23 21:47:53 +00:00
2025-09-23 21:47:53 +00:00

好的!下面给你标准答案最终可运行程序

PART 1选择题答案

  1. a
  2. c
  3. d
  4. b
  5. d
  6. d

PART 2编程

1) 游乐园身高/年龄判定(最终程序)

# 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" 应与整数比较(类型错误)
  • 打印时建议规范金额格式(逻辑/输出规范改进)

修正后的完整代码:

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))

需要的话我也可以给你一些快速测试用例,帮你验证输出是否符合预期。

Description
No description provided
Readme 29 KiB