Python在运行循环之前就停止了

时间:2017-10-10 10:41:05

标签: python

我在使用此代码时遇到问题。它将正常运行,直到它进入循环(def游戏)并停在那里。我确实把它作为一个if语句,但仍然没有用。请注意,这可能有点乱。

import random
import time 
GameInProgress = ("Yes")
TutorialDone = ("No")
ReplayGame = ("Yes")
#Test purposes
PlayerName = ("Lewis")
print ("Welcome to 'Guess The Word!")

def Game():
      GameInProgress = ("Yes")
      TutorialDone = ("No")
      ReplayGame = ("Yes")
      #Test purposes
      PlayerName = ("Lewis")
      print ("Welcome to 'Guess The Word!")
      WordSelected=("No")
      LettersGuessed=0
      print (TutorialDone)
      EnterName = input("Would you like to enter your name?").title()

1 个答案:

答案 0 :(得分:3)

def Game():不是循环,它是一个函数,直到你调用它才会执行。 你可以用这种方式调用python函数

Game()

如果你想一次又一次地调用同一个函数,只需在for或while循环中调用该函数:

   while(condition):
       Game()

如果您是初学者,请按照一些教程进行操作 https://www.tutorialspoint.com/python/python_functions.htm