我现在正在学习python,这是到目前为止我所掌握的代码,就像对条件语句之类的一些练习:
def the_flying_circus():
animals = raw_input("You are the manager of the flying circus. Which animals do you select to perform today?")
if animals == "Monkeys":
num_monkeys = raw_input("How many monkeys are there?")
if num_monkeys >= 20:
return "Don't let all of 'em hurt you!"
elif num_monkeys < 20 and num_monkeys >= 5:
return "Not too many, but be careful!"
elif num_monkeys < 5:
return "You're in luck! No monkeys to bother you."
elif animals == "Anteaters":
return "What the hell kinda circus do you go to?!"
elif animals == "Lions":
height_lion = raw_input("How tall is the lion (in inches)?")
if height_lion >= 100:
return "Get the hell outta there."
elif height_lion < 100:
return "Meh. The audience usually has insurance."
else:
return "Dude, we're a circus, not the Amazon rainforest. We can only have so many animals."
print the_flying_circus()
所以我现在遇到的问题是代码工作正常,直到我进入一个动物。如果我做食蚁兽,没关系。但是如果我做猴子或狮子,不管我输入什么数字,都只会打印出if语句首字母下面的字符串(“不要让它们伤害你”或“滚出去”)。我也没有收到任何错误。为什么会这样?在
^{pr2}$raw_input
返回一个字符串,需要将其转换为int
:原始输入将输入作为字符串。它应该转换成int
在代码中输入一个字符串,并将其与一个不应该进行比较的整数进行比较。键入cast您的输入
相关问题 更多 >
编程相关推荐