如何修复关于布尔变量和 if 语句的 python 代码
How to fix this python code about Boolean variables and if statements
问题:
Clunker Motors Inc. is recalling all vehicles in its Extravagant line from model years 1999-2002 as well all vehicles in its Guzzler line from model years 2004-2007. Given variables modelYear and modelName write a statement that assigns True to recalled if the values of modelYear and modelName match the recall details and assigns False otherwise.
代码:
if 1999 <= modelYear <= 2002 and modelName == "Extravangant":
recalled = True
elif 2004 <= modelYear <= 2007 and modelName == "Guzzler":
recalled = True
else:
recalled = False
查了别人的代码也搞不清楚缺什么
Extravangant
拼写错误。应该是Extravagant
。也许这就是问题所在。
问题:
Clunker Motors Inc. is recalling all vehicles in its Extravagant line from model years 1999-2002 as well all vehicles in its Guzzler line from model years 2004-2007. Given variables modelYear and modelName write a statement that assigns True to recalled if the values of modelYear and modelName match the recall details and assigns False otherwise.
代码:
if 1999 <= modelYear <= 2002 and modelName == "Extravangant":
recalled = True
elif 2004 <= modelYear <= 2007 and modelName == "Guzzler":
recalled = True
else:
recalled = False
查了别人的代码也搞不清楚缺什么
Extravangant
拼写错误。应该是Extravagant
。也许这就是问题所在。