Skip to content
Sign upLog in

Saving a score to put in displayIntro in python?

Profile icon
erger561

How do you save something that is before displayIntro() and then put it in displayIntro() with the same value?

You are viewing a single comment. View All
Profile icon
lolguineapig

@erger561
are you saying that you have a variable defined outside the function, and you want it to be defined in the function with the same value? If yes, you just have to use the keyword global.
Example:

var = input("What is your favorite color?") def hello(): return "Hello user. " + var + "is your favorite color!" print(hello())

That won't work ^
but this code will:

var = input("What is your favorite color?") def hello(): global var return "Hello user. " + var + "is your favorite color!" print(hello())