2

I imported choice from random and tried putting the functions I defined in a list, and I typed in:

print(choice([SonicTheHedgehogDrawing(), 
              turtle.KnucklesTheEchidnaDrawing(), 
              turtle.MilesTailsProwlerDrawing(), 
              turtle.BeanTheDynamiteDrawing(), 
              turtle.AmyTheHedgehogDrawing(), 
              turtle.EggmanDrawing(),
              turtle.RougeTheBatDrawing(), 
              turtle.BlazeTheCatDrawing()]))

I expected it to choose a random one of the functions, but it just starts with the first function, and then once it clears the screen, goes on to the next function in the list until its run them all.

001
  • 13,291
  • 5
  • 35
  • 66
  • Does this answer your question? [Why do the functions run as soon as my code runs? Turtle and TKinter problems](https://stackoverflow.com/questions/68430331/why-do-the-functions-run-as-soon-as-my-code-runs-turtle-and-tkinter-problems) – ggorlen Feb 17 '23 at 16:10

1 Answers1

2

By writing [SonicTheHedgehogDrawing(), turtle.KnucklesTheEchidnaDrawing(), turtle.MilesTailsProwlerDrawing(), turtle.BeanTheDynamiteDrawing(), turtle.AmyTheHedgehogDrawing(), turtle.EggmanDrawing(), turtle.RougeTheBatDrawing(), turtle.BlazeTheCatDrawing()] you create a list of the results of all the function calls. To collect the functions in a list before evaluating them, omit the braces (), like so: [SonicTheHedgehogDrawing, turtle.KnucklesTheEchidnaDrawing, turtle.MilesTailsProwlerDrawing, turtle.BeanTheDynamiteDrawing, turtle.AmyTheHedgehogDrawing, turtle.EggmanDrawing, turtle.RougeTheBatDrawing, turtle.BlazeTheCatDrawing]. But then you have to call the result of choice once:

print(choice([...])())
                   ^
                   |
                   |
                  here
user3389669
  • 799
  • 6
  • 20