Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x if/else发布Python3.4_Python 3.x_Spyder - Fatal编程技术网

Python 3.x if/else发布Python3.4

Python 3.x if/else发布Python3.4,python-3.x,spyder,Python 3.x,Spyder,因此,我正试图通过制作一个选择你自己的冒险游戏来学习python。我遇到的问题是,我无法让用户真正选择。我已经写了一堆内容,我想让用户在进入孔1或孔2之间进行选择。但是现在,当用户输入1或2时,什么也没有发生。它只是转到一个空行,不显示孔1/2的内容。我想我在存储用户输入然后重新调用时遇到了问题,但我不确定如何解决。理想情况下,当用户键入1或2时,他们将看到这些孔中的情况。我想再次指出,我是一个初学者,我相信有更好或更有效的方法来写这篇文章,但我的主要重点是让玩家进入第1洞或第2洞。我正在Spy

因此,我正试图通过制作一个选择你自己的冒险游戏来学习python。我遇到的问题是,我无法让用户真正选择。我已经写了一堆内容,我想让用户在进入孔1或孔2之间进行选择。但是现在,当用户输入1或2时,什么也没有发生。它只是转到一个空行,不显示孔1/2的内容。我想我在存储用户输入然后重新调用时遇到了问题,但我不确定如何解决。理想情况下,当用户键入1或2时,他们将看到这些孔中的情况。我想再次指出,我是一个初学者,我相信有更好或更有效的方法来写这篇文章,但我的主要重点是让玩家进入第1洞或第2洞。我正在Spyder3.x中使用Python3.6

def main():
    print('A giant ship comes crashing down in your swamp and ruins your possum and larvae soup.')
    print('A man emerges from the swamp. Gross he says. Why would anyone live in this shithole swamp?')
    print('Yoda emerges from his hut. I live here. I am Yoda, the talking swamp rat that will teach you how to kill your father.')
    begin = input("Do you want my help? Q=Quit. ")
    if begin.lower() !='q':
        print('Good lets begin') ##!='q': this is how you give someone the option to quit.
    else:
        print('good luck im going to eat some larvae and possum soup')
    userName = input("I have to ask. What is your name? ")
    print('Nice to meet you', userName,'Skywalker')
    print('Okay so first things first, lets get your ship out of my swamp. Great', userName, 'says.')
    print('But I will only do it if you catch me some possums. They are a delicassy here. They are in one of those 2 holes.')
    holeInput = input('Do you want to go into hole one or hole two? type one/two ')
    if holeInput == one: ##why won't this work? 
        print('You enter the hole. It is small and you have to crawl. All of a sudden there is a bright light.')
        print('You see a family of squirrels. Squirrels are not possums.')
        squirrel = input("Do you bring the squirrel to Yoda and hope he does not notice or do you leave? Quit means leave. Q=Quit." )
        if squirrel.lower() !='q':
            print('Congrats! you are now fighting a squirrel. You kill the squirrel in one blow and bring its carcass to Yoda.')
            print('You are a liar! Yoda says. I will not help you. Yoda goes inside and eats some possum and larvae soup.')
            return holeInput  
        else:
            print('You leave the hole to check the other hole.')
            return holeInput
    else:
        return holeInput

    if holeInput == two:
        print('You enter the hole. It is small and you have to crawl. All of a sudden there is a bright light.')
        print('You see a family of possums reading the space bible. One of the possums has glasses and a human face.')
        print('The possum turns to you. I am not a possum he says. My name is George Lucas the possum says. But it could be a lie. He really looks like a possum.')
        lucas = input("Do you listen to the talking possum? Quit means let him live. Q=Quit." )
        if lucas.lower() !='q':
            print('You kill the possum in one blow. You bring his body to Yoda. Wow! thats the biggest possum I have ever seen. You are a good guy and I will help you Yoda says.')
        else:
            print('You leave. Yoda calls you a failure.')
            return holeInput

main()   

您应该在数字或单词周围放置“或”:

if holeInput =='one':

因为用户输入是作为字符串返回的。所以这个值是1而不是1

作为补充说明,您可以检查多个正确值,因为您告诉用户输入一个或两个值,他们可能会实际键入“一”或“二”:

if holeInput=='1' or holeInput=='one':
我把它改成了 你想进入第一洞还是第二洞?类型1/2'
现在它将打印孔1/2的选项。感谢@user2357112的帮助

1在源代码中表示一个int。输入总是给你一个字符串。1是一个变量。一个是要比较的字符串。假设一个有很大区别=one@user2357112我把它改成holeInput=intinput‘你想进入第一洞还是第二洞?“1/2”型,它起作用了。谢谢或者如果输入{'1','1'}@Soroush谢谢。我意识到我和我的变量混淆了,现在我知道如果我想让用户输入数字/文本,如何标记输入/变量。谢谢是的,很好。实际上,如果holeInput在['1','one']中,它应该在括号中。花括号{}用于词典,而不是列表。
if holeInput=='1' or holeInput=='one':