218188d6fdb726b8ff7faeb679aa7a2483c881a1
好的!下面给你标准答案和最终可运行程序。
PART 1:选择题答案
- a
- c
- d
- b
- d
- 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