没有错误, 但当我运行它, 它显示一个白色屏幕

共2个回答, 标签: python

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

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

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!')

    while php >0 and shp >0:
        choice = ('z')
        while choice != ('a'):
            print ('What u gonna do')
            print ('    a) Fight you strong man or woman')
            print ('    b) Run away because you are soooo scared that you do not want to fight')
            print ('    c) Look at dem stats booooiiii')
            choice = input()
            if choice == ('a'):
                print('You attack like a man (or woman)')
            if choice == ('b'):
                print ('you run away')
                print ('nevermind the ' +adj + spawn+ ' eats like you like a very hungry guy at McDonalds ' )
                php =0
                break
            if choice == ('c'):
                print('your own stats boooiiii')
                print('Attack = ' +str(patt)+ '   Defense = ' +str(pdef)+ '  Health = ' +str(php)+ '  Gold = ' +str(pgold) )
                print(adj + spawn+ '''\'s stats''')
                print('Attack = ' +str(satt)+ '   Defense = ' +str(sdef)+ '   Health = ' +str(shp) )
            if choice ==('a'):
                pattroll = random.randint(1,50)
                if pattroll >= sdef:
                    damage = random.randint(1,50)
                    print('You attack the  ' +adj + spawn+ ' and according to my calculations you did ' +str(damage)+ '!')
                    shp = shp - damage
                if pattroll < sdef:
                  print('you miss')
                  if shp >0:
第1个答案

除了其他问题/凹痕外, 您没有调用任何函数。
您可以将以下代码放在文件的末尾, 看看它是否有效 (或显示任何错误):

if __name__ == "__main__":
    main()
第2个答案

您根本不调用任何函数, 考虑到您已正确缩进代码, 而没有复制的函数名称, 这就是结束脚本的外观

def main():
    # your  code here

if __name__ == "__main__":
    main()

相关问题

通过随机抽样其他列数据创建新列 如何使用熊猫获得包括每一个组合的计数 如何有效地展开矩阵的值与小块?