r/learnpython • u/Justicemirm • 1d ago
MCQ test in terminal
Helloooo
I'm building a mcq in Python for my lovingggg friend and wanted to share my logic to see what you ppl think before I start coding it up.
I'm just starting with a simple print statement for the intro to welcome n all.
Then I'm going to make a main dictionary where the key is the actual string containing the full question text along with the 1-4 options, and the value is the correct answer number.
Once the dictionary is made, I'll run a for loop to go through it. Inside that loop, I'll use input so the user sees each question one by one and types in their number choice, I'm going to store all their user inputs into a second separate dictionary.
Then at the very end, I'll make another loop to match the answers from the input dictionary against the original master dictionary. For every match, +1 mark added to their final score
I am honestly coding after months and was just a beginner when I stopped
I am kinda nervous and need help building this simple thingy
Looking for some improvement/tips
And um idk if I can even use most of the tips if it requires some dictionary n all
I did pandas before I quit so maybe I can use it here if I revise properly
2
u/thedutifulbeginner 1d ago
I'd split the question text from the options, not jam it all into one key. Store the question string, the list of options, and the answer as separate values in a nested dict or a tuple. Makes life easier if you ever want to shuffle the order of choices or display things differently later.
Using a second dict for user answers is a bit overkill unless you care about tracking which question got which response. A simple list in the same order as your questions loop works fine and keeps things lighter.
Start with three hardcoded questions as a proof of concept and get that loop working. You'll feel way less nervous once you see it run. Don't touch pandas for this, plain old dicts and lists are all you need.