【发布时间】:2015-11-16 01:22:31
【问题描述】:
学习 Python 才几个月,所以请耐心等待......
创建一个非常简单的游戏作为 Python 教程的一部分,其中基本上用户从一个班级跳到另一个班级,所有这些都需要用户输入并打印出各种语句。
例如,给定以下类:
class ChipCar(Scene):
def enter(self):
print "What's up? Get in the Bran Muffin car!"
action = raw_input("> ")
if action == "shut up chip":
print "Screw you!"
print action
return next_scene('Your_death')
#return 'Death'
elif action == "hi chip":
print "What's up loser?!?! Let's go to O&A..."
return next_scene('Chip_in_studio')
else:
print "what's wrong with you? Let's go to my mother's house, I think Lamar's there..."
return 'Chip_mom_house'
假设我希望能够检查第一个 if 语句的多个正确选项,例如,除了 "shut up chip" 之外还有 "go away dude" 或 "screw you" 或 "Java sucks" — 最好的方法是什么?
【问题讨论】:
-
哇,有很多选择......有点违背 Python 哲学,嗯?关于“应该有一种——最好只有一种——明显的方式来做到这一点。”
标签: python python-2.7 conditional-statements