Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.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 如何使用if语句检查函数内部的变量?_Python_Python 3.x - Fatal编程技术网

Python 如何使用if语句检查函数内部的变量?

Python 如何使用if语句检查函数内部的变量?,python,python-3.x,Python,Python 3.x,我正在做一个基于文本的黑客游戏。如何使用if语句检查函数内部的变量 错误: Traceback (most recent call last): File "C:\Users\user\Desktop\Python Projects\TextHackingGame\Start.py", line 22, in <module> if check == "start": NameError: name 'check' is not defined 声明变量时,请使用che

我正在做一个基于文本的黑客游戏。如何使用if语句检查函数内部的变量

错误:

Traceback (most recent call last):
  File "C:\Users\user\Desktop\Python Projects\TextHackingGame\Start.py", line 22, in <module>
    if check == "start":
NameError: name 'check' is not defined

声明变量时,请使用
check=0
check=0
,并在函数中使用
StartOrChange()

def StartOrChange():
     global Check
     global check

     print("Type 'Start' or 'Changelog'.")
     Check = input("> ")
     print (Check) 
     check = Check.lower() 

global
进入一个试图更改全局值的函数。请确保此处的缩进与文件中的缩进相同。如果是相同的,那就是你的问题所在。
def StartOrChange():
     global Check
     global check

     print("Type 'Start' or 'Changelog'.")
     Check = input("> ")
     print (Check) 
     check = Check.lower()