有人可以检查我的代码 [英] Can someone please check my code

查看:65
本文介绍了有人可以检查我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法理解为什么我的代码没有运行,这段代码是用python编写的,我试图制作一个Minecraft文本冒险游戏,每当我打开它立即退出的程序时,如果你知道问题可以你请帮助,但如果你没有,那么请你告诉我该怎么做,所以我至少可以看到我得到的错误信息。谢谢。这是我正在尝试的项目代码。



I cannot seem to understand why my code is not running, This code was written in python and I was trying to make a minecraft text adventure game, whenever I open up the program it exits out immediatly, If you know the problem could you please help but if you do not then could you please tell me what to do so I can at least see the error message that I am getting. Thank you. here is the code for the project that I am trying to work on.

print ('Welcome to the homepage of your program!')
print ()
print('Would you like to enter your information')
print ('Please enter yes or no')
yesorno = input()
if yesorno == 'yes':
    print()
    print("Please enter your name")
# This is how you would run script from another python file
# exec(open('Your Python File.py').read())
# the file that you are going to open has to be in the same directory
# as the file that we are coding right now (or the file that you are coding)
# You can also open up text files as well I think
    name = input()
    print()
    print('It is nice to meet you', name)
    print()
    print('Please enter your age')
    age = input()
    print('You will be', int(age) + 1, 'next year')
    print()
if yesorno == 'no':
    print ('Then please continue with the rest of the program')
print ('Would you like to play a text adventure game? or would you like to learn to code?')
answer = input()
if answer == 'text adventure game':
    print ('Which text adventure game would you like to play')
    print ('The current games that we have are Minecraft')
    whichgame = input()
    if whichgame == 'Minecraft':
        print ('You spawn in a welcoming world with mobs, caves, and lots of animals')
        print ('What is the first thing that you want to do?')
        print ('Your options are mine trees, get food, get wool, go exploring')
        whattodonext = input()
        if whattodonext = 'Enter a cave':
            print ('There was a bunch of skeletens and zombies in the cave, you are dead, sorry!')
        elif whattodonext = 'get food':
            print ('You see a cow, a chicken, a sheep, and a pig, which one would you like to kill first')
            print ('Please enter cow, chicken, sheep, or pig')
            killfirst = input()
            if killfirst == 'cow':
                print ('Congratulations, You have got some food!')
            elif killfirst == 'chicken':
                print ('Yay you have got one piece of chicken!')
            elif killfirst == 'sheep':
                print ('You have got some wool and food! That is a great start')
            elif killfirst == 'pig':
                print ('Sorry! The pig that you were trying to kill has fallen into a ditch')
        elif whattodonext == 'mine trees':
            print ('How many trees do you want to mine')
            print ('You can mine up to 10 trees, please enter a number')
            numberoftrees = input()
            if numberoftrees == '1':
                # type code inside here
                print ('You have four pieces of oak wood')
                print()
                print ('Would you like to create a crafting table')
                createacraftingtable = input()
                if createacraftingtable == 'yes':
                    print ('You are going to need more wood to create something with this crafting table')
            elif numberoftrees == '2':
                # type code inside here
            elif numberoftrees == '3':
                # type code inside here
            elif numberoftrees == '4':
                # type code inside here
            elif numberoftrees == '5':
                # type code inside here
            elif numberoftrees == '6':
                # type code inside here
            elif numberoftrees == '7':
                # type code inside here
            elif numberoftrees == '8':
                # type code inside here
            elif numberoftrees == '9':
                # type code insider here
            elif numberoftrees == '10':
                # type code inside here
    elif whichgame == 'I do not want to play a game':
        print ('Then please feel free to exit out of this program and try again some other time')





我尝试了什么:



我试过调试我的代码,但我似乎无法弄清楚我的程序出了什么问题,所以我要求你们所有人帮忙。我非常感谢有关此问题的一些帮助或反馈。



What I have tried:

I have tried debugging my code but I could not seem to figure out what is wrong with my program, So I am asking all of you guys for help. I would really appreciate some help or feedback on this issue.

推荐答案

在Python shell中运行它会立即返回以下内容:

Running it in the Python shell it comes back immediately with the following:
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import mine
  File "C:\Users\rjmac\Documents\Python\mine.py", line 35
    if whattodonext = 'Enter a cave':
                    ^
SyntaxError: invalid syntax



这表明您忘记了if语句中的第二个等号。


Which shows that you forgot the second equals sign in your if statement.


这篇关于有人可以检查我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆