I'm a newbie programmer trying to make a program, using Python 3.3.2, that has a main()
function which calls function1()
, then loops function2()
and function3()
.
My code generally looks like this:
def function1():
print("hello")
def function2():
name = input("Enter name: ")
def function3():
print(name)
def main():
function1()
while True:
funtion2()
function3()
if name == "":
break
main()
Currently, I get the following error when I run the program and enter a name:
NameError: global name 'name' is not defined
I understand that this is because name
is only defined within function2()
. How do I make it so that name
is defined as a 'global name', or somehow be able to use it within function3()
and main()
.
Thanks in advance.