How can I use if statements to check variables inside of function? [duplicate]

Multi tool use


How can I use if statements to check variables inside of function? [duplicate]
This question already has an answer here:
I am making a text based hacking game. How can I use if statements to check variables inside of function?
Error:
Traceback (most recent call last):
File "C:UsersuserDesktopPython ProjectsTextHackingGameStart.py", line 22, in <module>
if check == "start":
NameError: name 'check' is not defined
The code:
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'")
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
global <name>
Make sure you indentation is the same here as in your file. If it's the same, that's where your issue is.
– Liora Haydont
yesterday
1 Answer
1
When you declare your variables, use check = 0
and Check = 0
, and inside the function StartOrChange()
use
check = 0
Check = 0
StartOrChange()
def StartOrChange():
global Check
global check
print("Type 'Start' or 'Changelog'.")
Check = input("> ")
print (Check)
check = Check.lower()
https://docs.python.org/3/faq/programming.html
1v3GbpQiZIeMhpELKUHGj f,Zr,OHOCj3 pk QAvlr7R,6pB6ZF9PiR9c YAzNsm NfUaLHT6SNArywDBtBBuGe2nlc
global <name>
goes inside a function that tries to alter the global.– Martijn Pieters♦
yesterday