Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGeoArmani Lovinaria
1,098 PointsNeed guidance on coding a function quiz for myself in Python.
So I decided to code a function quiz to help me study in Python as well as get some coding practice in. Below is a snapshot of where a I started. Just a heads up I only start learning python a few days ago on this platform. The file name is functionflashcard.py
Now one of my questions is how can I create a loop back to the beginning if the input is wrong, and is there a way to create a function for python to ask the next question on the quiz with out repeating the same long lines of code over and over again. Also, I'm still super beginner so the answers may be ahead in my course that I haven't reached yet. Thank you ahead of time!
1 Answer
Steven Parker
231,269 PointsI applaud your enthusiasm, but you're right, all these things will be coming shortly as you progress in the lessons. Some particular concepts that will help do what you want are:
- loops — will let you go back to the beginning, and also reduce repeated code
- functions — to ask multiple questions without repeating lots of code
- lists — will give you a way to store questions and answers more compactly
I see you have already used functions in check_please.py and notifications.py. You might try writing a function that asks a question and checks the answer. With that, the rest of the program would be just two function calls.
And for extra practice, as you learn each other concept, you could come back to this project an apply your new skills to refine your program.
Happy learning!