Making a quiz with shuffled questions

2024/11/16 23:35:48

I am wanting to join the Royal Air Force and thought as a good way to prepare I should code myself a quiz about their aircraft.

There are 28 aircraft that I have added to the quiz. For example - 'Where is the Typhoon FGR4 based?' And then I have 7 seconds to think before the options pop up for me to answer.

Instead of the quiz just going from the first to last question in the same order each time I would like it to be shuffled.

Here is the quiz in pastebin http://pastebin.com/wxVus42W

Also when I have answered the question I would like the console to clear itself for the next question to come up.

Can anyone help?

Thanks

Answer

dont repeat yourself!, create methods, add your question and the excepted answer as flag

import timedef create_question(question = "", answer = "", excepted = ""):print (question)time.sleep(7)print(answer)while True:response = input("Hit 'a', 'b', 'c' or 'd' for your answer\n")if response == excepted:#CHANGEprint ("Correct!\n")breakelse:print("Incorrect!!! Try again.")while True:response = input("Hit 'a', 'b', 'c' or 'd' for your answer\n")if response == excepted:#CHANGEprint ("Correct!\n")#CHANGEstop = Truebreakelse:print("Incorrect!!! The Tornado GR4 is based at RAF Marham\n")#CHANGEstop = Truebreakif stop:break#first question               
create_question(question = "Where is the Tornado GR4 based?",answer = "a. RAF Marham\nb. RAF Conningsby\nc. RAF Waddington\nd. RAF Church Fenton\n",excepted = "a")
#second question                
create_question(question = "Where is the Typhoon FGR4 Based?",answer = "a. RAF Marham\nb. RAF Conningsby\nc. RAF Benson\nd. RAF Wyton\n",excepted = "b")
https://en.xdnf.cn/q/118868.html

Related Q&A

How to create a timer that resets for quiz games?

I trying to create a timer for my quiz game. It should reset after every right question. But problem with my code is that it keeps increasing speed after every time it resets. timeCount = 30 def countd…

Stucking of python multiprocessing.pool

i have multiprocessing script with "pool.imap_unordered". I ran into a problem when the script got stuck but i check CPU usage — nothing happening (by "top" command on ubuntu). Goi…

python: merge two csv files

I have a problem while Im doing my assignment with python. Im new to python so I am a complete beginner.Question: How can I merge two files below?s555555,7 s333333,10 s666666,9 s111111,10 s999999,9and…

Generate a custom formated string with python

I have a Javascript code that generates a string (similar to uuid) stringHere it is the js code: var t = "xxxxxxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxxx", i = (new Date).getTime(); return e = t.repla…

PySide-6.6: clicked signal sends extra boolean argument to slot

I just upgraded PySide6 (PySide6==6.6.0 from 6.2.2) and a new behavior is wreaking havoc with my GUI program. Every place where I have a clicked signal, the hooked up slot is receiving an extra bool==F…

SMTPConnectError when using Django

Im using django-registration for handling of users registration. I tried to signup in order to test it, after testing it, I got this errorSMTPConnectError at /accounts/register/Being trying to find a s…

how to have a single search API using path parameters (No form used)

I have been using this view for searching a word as:db refers mongo connection (just for ref)@app.route(/) def index():return render_template(index.html)@app.route(/words-<word>, methods=[GET, PO…

understanding the return type of anonymous function lambda

I am trying to understand how can lambda function be used. def adder_func(a, b):return a + bprint(adder_func(4, 5))# trying with lambda print(list(lambda a, b: a + b))When trying to use lambda as a add…

What is the meaning of Failed building wheel for flask-mysqldb in pip3 install?

I have a MacBook Air with macOs Sonoma 14.0 and when I write in the terminal $ pip3 install flask-mysqldbI get the error:How can I fix this?

How do I install pygame for a new version of idle? (Windows) [duplicate]

This question already has answers here:Error on install Pygame(3.9) install (Win10) [duplicate](1 answer)Unable to install pygame on Python via pip (Windows 10)(6 answers)Closed 3 years ago.I installed…