Python Forum
Python 3 Global Variable Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 3 Global Variable Help
#2
If you would do it this way
# Start Game
name = '' 
levelone()
print(name)
it would work BUT THIS VERY BAD CODE STYLE! DON`T DO IT THIS WAY! NEVER USE GLOBAL!

Define your functions to get parameters/arguments and RETURN variables that your other code need.
If you would change your last lines in your function levelone()
            # global name # or DELETE this line
            name = input('your name: ')
            line = "Hello, {}, welcome to the Gryphon's den, do you remember from anything before you got here?".format(name)
            print(line)
            return name
and would then call this function like
name = levelone()
print(name)
this would provide you with the name the user inputted.

BUT, and now it´s your turn: What is the value of name if your function is exited before the user inputs his name and how can you solve that?

BTW: the amount of BREAKs in your code is not pythonic. Rethink this also.
Reply


Messages In This Thread
Python 3 Global Variable Help - by Tridium - Jul-28-2019, 03:24 AM
RE: Python 3 Global Variable Help - by ThomasL - Jul-28-2019, 06:32 AM
RE: Python 3 Global Variable Help - by Tridium - Jul-28-2019, 07:49 AM
RE: Python 3 Global Variable Help - by ThomasL - Jul-28-2019, 06:48 PM
RE: Python 3 Global Variable Help - by Windspar - Jul-28-2019, 01:31 PM
RE: Python 3 Global Variable Help - by Tridium - Jul-29-2019, 08:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Time to Update a Global Variable and Label in TkInter cameron121901 5 4,129 Apr-22-2019, 05:08 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020