猿问

没有错误,但是当我运行它时,它显示白屏

我使用trinket.io 编写了一个相当大的代码。后来我做了一个商店,然后是一个保存功能。有一次,我做了一个保存功能,代码停止工作。


我已经尝试修复缩进修复拼写错误将代码放入新的 python 程序。


def main():

  reward = 0

  patt = 20 

  pdef = 10

  php = 35

  pgold= 0

  pgold = pgold + reward

  name = input("what is your name")

  print('''You are ''' +name+ ''' and you're trying to escape from the zoo but OUTTA NOWHERE A...''')

  save()


  def save():

    import random

    import time


    name = input("what is your name")

    print('''You are ''' +name+ ''' and you're trying to escape from the zoo but OUTTA NOWHERE A...''')


    number1 = random.randint(1,7)

    if number1 == 1:

        spawn = ' Monkey God'

        satt = 1000

        sdef = 9999

        shp = 1000000


    elif number1 == 2:

        spawn = ' Howard the alien'

        satt = 0

        sdef = 1

        shp = 1


    elif number1 == 3:

        spawn = ' Evan'

        satt = random.randint(4,21)

        sdef = random.randint(21,99)

        shp = random.randint(1,50)


    elif number1 == 4:

        spawn = ' Game Katana'

        satt = random.randint(1,500)

        sdef = random.randint(4,25)

        shp = random.randint(5,25)


    elif number1 == 5:

        spawn = ' John Cena'

        satt = 50

        sdef = random.randint(1,42)

        shp = 25


    elif number1 == 6:

        spawn = ' Willy Wonka'

        satt = random.randint(1,50)

        sdef = random.randint(1,50)

        shp = random.randint(1,50)

    else:

        spawn = ' Jax'

        satt = random.randint(1,25)

        sdef = random.randint(1,25)

        shp = random.randint(1,25)


    number2 = random.randint(1,4)

    if number2 == 1:

        adj = 'cringey'

        satt = satt -25


    elif number2 == 2:

        adj = 'OP'

        sdef = sdef +40


    elif number2 == 3:

        adj = 'demonic'

        shp = shp +30


    else:

        adj = 'angelic'

        sdef = sdef +3

    print ('random ' +adj + spawn+ ' appeared!')


我希望代码能够运行并显示一些东西,即使它有问题我可以解决这个问题,但是,我想工作。(而且我在编码方面真的非常非常糟糕。所以请记住这一点。)


慕姐4208626
浏览 160回答 2
2回答

Cats萌萌

您根本没有调用任何函数,考虑到您已正确缩进代码,没有复制函数名称,这就是结束脚本的样子def main():    # your  code hereif __name__ == "__main__":    main()

不负相思意

除了其他问题/缩进之外,您没有调用任何函数。您可以将以下代码放在文件末尾,看看是否有效(或显示任何错误):if __name__ == "__main__":    main()
随时随地看视频慕课网APP

相关分类

Python
我要回答