stage.set_background_color("blue")
sprite = codesters.Sprite("flower4")
sprite.set_size(2)
##########
# this is a global variable,
# we are declaring it outside of a function
score = 0
def changeMyVariable(number):
# but to use it inside of a function, we have to do this
global score
# if we don't use the global keywork, the function things
# we want to use a NEW variable named score
score = number
printMyScore()
stage.wait(2)
def printMyScore():
global score
sprite.say(score)
changeMyVariable(2)
changeMyVariable(7)
changeMyVariable(4)
changeMyVariable(2)
-
Run Code
-
-
Stop Running Code
-
Show Chart
-
Show Console
-
Codesters How To (opens in a new tab)