我正在制作基于文本的黑客游戏。如何使用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
代码:
import time
import string
import os
import sys
print("-------------------------")
print("Welcome to [NAME_HERE]")
print("By ***************")
print("Copyright 2018")
print("-------------------------")
time.sleep(0.10)
os.system("cls")
global Check
global check
def StartOrChange():
print("Type 'Start' or 'Changelog'.")
Check = input("> ")
check = Check.lower
if check == "start":
pass
elif check == "changelog":
pass
else:
print("Please enter 'Start' or 'Changelog'")
答案 0 :(得分:0)
声明变量时,请使用check = 0
和Check = 0
,在函数StartOrChange()
中使用
def StartOrChange():
global Check
global check
print("Type 'Start' or 'Changelog'.")
Check = input("> ")
print (Check)
check = Check.lower()