Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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测试项目)_Python_Python 2.7 - Fatal编程技术网

这段代码有什么问题?(Python测试项目)

这段代码有什么问题?(Python测试项目),python,python-2.7,Python,Python 2.7,我用Windows10编写了python代码。它一直重新启动,没有显示任何内容 请帮忙 这个问题一直在发生。我重新启动了ide,并尝试使用在线ide。任何有助于解决此问题的信息都将大有帮助 import time global apples global gold apples = 0 gold = 0 def start(): print "Hello" print "My name is Jason" name = raw_input("What is your N

我用Windows10编写了python代码。它一直重新启动,没有显示任何内容

请帮忙

这个问题一直在发生。我重新启动了ide,并尝试使用在线ide。任何有助于解决此问题的信息都将大有帮助

import time
global apples
global gold
apples = 0
gold = 0

def start():
    print "Hello"
    print "My name is Jason"
    name = raw_input("What is your Name?")
    print "Welcome "+name+"."
    print "The object of this game is to pick apples and sell them for gold."
    time.sleep(1)
    begin = raw_input("Would you like to play?")
    print "Y or N"
    if begin == "Y":
        time.sleep(1)
        begin()
    if begin == "N":
        print "Okay, Please exit the terminal."
        print "Goodbye!!!"
def begin():
    papple = raw_input("Would you like to Pick some Apples?")
    print "Y or N"
    if papple == "Y":
        time.sleep(1)
        apples=apples+5
        print "Computer: You picked 5 apples."
        print "You now have "+apples+"!!!"
        begin()
    if papple == "N":
        sell = raw_input("Would you like to sell some apples for gold?")
        print "Y or N"
        if sell == "Y":
            time.sleep(1)
            gold=gold+5
            apples=apples-5
            print "Computer: You sold 5 Apples for 5 Gold."
            print "You now have "+apples+" apples, and "+gold+" Gold Pieces."
            begin()
        if sell == "N":
            print "Okay"
            begin()

我没有看到任何可以启动函数的东西。尝试添加

if __name__ == '__main__':
    start()
还有很多其他的错误。如果您不想通过缓慢调试自己来学习完整代码:

import time
apples = 0
gold = 0

def start():
    print "Hello\n"
    print "My name is Jason\n"
    name = raw_input("What is your Name?\n")
    print "Welcome %s.\n" % name
    print "The object of this game is to pick apples and sell them for gold.\n"
    time.sleep(1)
    begin = raw_input("Would you like to play?\nY or N\n")
    if begin == "Y":
        time.sleep(1)
        beginfunction()
    if begin == "N":
        print "Okay, Please exit the terminal.\n"
        print "Goodbye!!!\n"
def beginfunction():
    global apples
    global gold
    papple = raw_input("Would you like to Pick some Apples?\nY or N\n")
    if papple == "Y":
        time.sleep(1)
        apples=apples+5
        print "Computer: You picked 5 apples.\n"
        print "You now have %s apples!!!\n" % apples
        beginfunction()
    if papple == "N":
        sell = raw_input("Would you like to sell some apples for gold?\nY or N\n")
        if sell == "Y":
            time.sleep(1)
            gold=gold+5
            apples=apples-5
            print "Computer: You sold 5 Apples for 5 Gold.\n"
            print "You now have '%s' apples, and '%s' Gold Pieces.\n" % (apples, gold)
            beginfunction()
        if sell == "N":
            print "Okay\n"
            beginfunction()

if __name__ == "__main__":
    start()

首先,您没有调用上面定义的任何函数

main():
    begin()
    start()
然后使用

if __name__ == '__main__':main()

有错误信息吗?