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

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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> goes inside a function that tries to alter the global.
– Martijn Pieters
yesterday


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
LnNOnrv3G,9oY7GoRWoUlEnrfm6,S9C,iBxfcMjJK5l0tX9vafGEb lHqXIfct,YcGodDwVjp,k0i jme

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template