困在第36个练习中艰难地学习Python
这是我为练习36编写的代码。但是我无法运行困在第36个练习中艰难地学习Python,python,python-2.7,Python,Python 2.7,这是我为练习36编写的代码。但是我无法运行door_1功能中的代码。如果我选择3作为选项,然后向左或向右选择任何存储在dir中的内容,那么无论我键入什么,输出都是“lion吃了你” from sys import exit #importing module from lib def Tadaa(): print "This is a place where you will get a surprise" next = int(raw_input("Enter any num
door_1
功能中的代码。如果我选择3作为选项,然后向左或向右选择任何存储在dir中的内容,那么无论我键入什么,输出都是“lion吃了你”
from sys import exit #importing module from lib
def Tadaa():
print "This is a place where you will get a surprise"
next = int(raw_input("Enter any number from 1-10 :"))
if next <= 10:
if next % 2 == 0 :
print "You will be buying me a shake :)."
else :
print "You will be getting a shake by me."
else :
print "Do it correctly."
def door_1():
print "There are 3 doors . Choose any door from the the remaining three doors"
print "Lets hope for the best "
next = raw_input("Enter your option :")
if next == "1":
print "abc "
elif next == "2":
print "abc"
elif next == "3":
print "You have entered 3rd door ."
print "Here are 2 doors one on left and one on right."
dir = raw_input("Choose which door do you wnat to enter :")
if dir == "left" or "Left":
print "Lion ate you . You are dead ."
elif dir == "right" or "Right" :
print "You will be getting a surprise"
Tadaa()
else :
print "abc"
else :
print "abc"
def door_2():
print "There are two doors A and B which will decide your fate"
next = raw_input("Enter the door ")
if next == "A" or "a":
door_1()
elif next == "B" or "b":
print "You are back from where you have started"
start()
else :
print "I got no idea what that means."
exit(0)
def start():
print "You are in dark room"
print "There is a door to your right and left ."
print "Which one do you take"
next = raw_input("> ")
if next == "Right" or "right":
door_2()
elif next == "Left" or "left":
door_1()
else :
print "abc"
start()
从系统导入退出#从库导入模块
def Tadaa():
打印“这是一个你会得到惊喜的地方”
next=int(原始输入(“输入1-10之间的任意数字”))
如果下一步问题在于你的陈述:
if dir=="left" or "Left":
你想要的是
if dir=="left" or dir=="Left":
实际上,刚才所做的或“Left”
就是检查您刚刚创建的字符串是否存在。换句话说,它类似于:
x='Left'
if x:
X确实存在,所以如果X
为True
这里的关键是始终在quantum中计算语句,当您将
和
与或
语句结合使用时,请确保使用括号来明确表示<代码>如果语句\u-one或语句\u-two但如果您看到start()函数,您将看到我对下一个语句也做了同样的操作,但它确实运行。我现在还不确定,但我可以告诉你一个事实,那就是如果语句不正确,你是如何评估的:)按照上面演示的方法正确操作,看看这是否解决了你的问题。如果你知道下一个语句,一定要让我知道:)就像我说的,把它全部解决。例如,如果next=='Right'或next=='Right',则应该使用。我不知道为什么它现在似乎工作得很好,但我相信它的错误代码和它的工作只是侥幸。调试代码很好,调试函数代码有时很难。