To finish off the superturtle app, we are going to add the following to our program:
Move the printing of the menu options to the helper function, but run it in main.py
Add at least 3 new methods to the SuperTurtle class (whatever you want, but they should be obviously different than the things we wrote together.
Let's get a little crazy here and build a pretty sophisticated app. We're building a SuperTurtle class with lots of methods. We've built some helper functions to provide random colors or print welcome messages. And we're building an interactive menu structure to run the whole app. But if we put all of this stuff in one file it gets to be a real mess. So let's split everything up like professional software developers.
Let's make a new Python Trinket. Call it Final Turtle and save it. Then create a new file called superturtle.py. Notice that we don't include capitals or spaces in the names of our module file.
Now let's add our SuperTurtle class to this file. You can start with my copy below and then add in additional methods you may have built in our previous Trinkets.
We're going to make a file with a bunch of helpful functions. Let's call it helper.py
And let's add this code:
In order to access the rancolor()
function from helper.py, we could import that specific function with from helper import rancolor
But what'd I'd rather do, is just import helper
at the top and then change the rancolor line to helper.rancolor()
Let's add a basic menu to our app:
Try changing this project. Add options and features. I'm here to help, too.
The gang of turtles is in the main file. If we want to use it in the helper.py file, we need to pass it as a parameter. For example, I could add this method to my helper file that will make each turtle draw 100 stars:
And perhaps I want to add this super_star option to my menu. So I'll add it to my print_options
and to my main.py
's if statements:
1pt - separate SuperTurtle class and module
1pt - separate helper module
2pts - multiple adds to menu
2pts - first added method
2pts - second added method
2pts - third added method
2pts - creative display