Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Using Databases in Python!
You have completed Using Databases in Python!
Preview
We can start to get into the actual behavior of our application now. We'll use an OrderedDict to hold onto our choices and a nifty trick to print out the options to the user and then run their selected function.
New terms
-
OrderedDict- a handy container from thecollectionsmodule that works like adictbut maintains the order that keys are added -
.__doc__- a magic variable that holds the docstring of a function, method, or class
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
But it has multiple possibilities or cases
as they're often called.
0:00
Python doesn't have switches.
0:00
And this is an intentional omission.
0:02
Switches, are often a source of bugs and
can be really confusing for people.
0:04
We can, however, use a dictionary as a
list of triggers and their actions.
0:08
Dictionaries though, as you remember,
don't have an order.
0:12
No one wants a menu that keeps moving
around them.
0:15
So, I'm gonna introduce you to a handy
tool known as an ordered dict.
0:18
Every time we've built a menu so far, it's
been, pretty simple, just one or
0:22
two choices that we've been presenting to
the users,
0:26
as a string inside of the input function.
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up