Python在运行循环之前停止

2024-05-29 00:11:45 发布

您现在位置: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()

Tags: tonotestimportdefyesprintguess
1条回答
网友
1楼 · 发布于 2024-05-29 00:11:45

def Game():不是循环,它是一个函数,在您调用它之前它不会执行。 可以这样调用python函数

Game()

如果要反复调用同一个函数,只需在for或while循环中调用函数:

   while(condition):
       Game()

如果你是初学者,请遵循一些教程 https://www.tutorialspoint.com/python/python_functions.htm

相关问题 更多 >

    热门问题