【发布时间】:2016-04-09 04:01:44
【问题描述】:
使用 python 2.7.6 版
我用python写了一个简单的谜语(来自哈利波特),当命令行提示用户时,他们必须输入“1”两次,“2”三次,“3”四次(等等。 ) 以获取他们想要选择的选项。我知道我错过了什么,但不知道是什么。
#potter_riddle
print " "
print "Pick Your Poison, Potter"
ascii_bottles = """
#########################################################
# _ #
# ( ) _ #
# _ ___ _ ___ / \ ( ) #
# / \ ( ) _ ( ) | | | | / \ #
# | | / \ / \ / \ | | | | | | #
# |___| (_____) (___) (___) |___| |___| |___| #
# 1 2 3 4 5 6 7 #
# #
#########################################################
"""
riddle = """
Danger lies before you, while safety lies behind,
Two of us will help you, whichever you would find,
One among us seven will let you move ahead,
Another will transport the drinker back instead,
Two among our number hold only nettle wine,
Three of us are killers, waiting hidden in line.
Choose, unless you wish to stay here for evermore,
To help you in your choice, we give you these clues four:
First, however slyly the poison tries to hide
You will always find some on nettle wine\'s left side;
Second, different are those who stand at either end,
But if you would move onwards, neither is your friend;
Third, as you see clearly, all are different size,
Neither dwarf nor giant holds death in their insides;
Fourth, the second left and the second on the right
Are twins once you taste them, though different at first sight.
"""
def answer():
if "1" in raw_input():
print "Hermione\'s advice was terrible! Now you\'re dead and Voldemort wins."
elif "2" in raw_input():
print "You\'re a little drunk. Try again."
elif "3" in raw_input():
print "Congratulations! Now go find Professor Quirrel."
elif "4" in raw_input():
print "Hermione\'s advice was terrible! Now you\'re dead and Voldemort wins."
elif "5" in raw_input():
print "Hermione\'s advice was terrible! Now you\'re dead and Voldemort wins."
elif "6" in raw_input():
print "You\'re a little drunk. Try again."
elif "7" in raw_input():
print "What the hell are you doing back in the Chess Room?"
else:
print "No, you cannot use a spell to get out of this. Try a number."
print ascii_bottles
print riddle
print "Which bottle shall you try?"
raw_input("> ")
answer()
回答 1 会导致:
Which bottle shall you try?
> 1
1
Hermione's advice was terrible! Now you're dead and Voldemort wins.
回答 7 个结果:
Which bottle shall you try?
> 7
7
7
7
7
7
7
7
What the hell are you doing back in the Chess Room?
任何建议将不胜感激......
【问题讨论】:
标签: python python-2.7 if-statement output