Question
this is the question Create a quiz program using all the questions and answers provided below You're 3rd place right now in a race. What
this is the question
Create a quiz program using all the questions and answers provided below
You're 3rd place right now in a race. What place are you in when you pass the person in 2nd place?
1st
2nd
3rd
4th
How many months have 28 days?
All of them.
1
Depends if there's a leap year or not.
2
If a leaf falls to the ground in a forest and no one hears it, does it make a sound?
Yes
No
Depends on how heavy the leaf was.
Depends on what's on the floor
There are 45 apples in your basket. You take three apples out of the basket. How many apples are left?
45
3
42
0
Mathew's father has three sons- Joseph I and Joseph II. Can you guess the name of the third son?
Mathew
Joseph III
Jerin
John
What is the name of the company that published the Mario Kart video game?
Nintendo
Electronic Arts (EA)
SEGA
Xbox
- Show the correct answers when user selected a wrong option
- Randomly choose a congratulatory phrase from Good job! Awesome!, Correct! when user selected a correct option
- At the end of the quiz, show the score
Each question has four options (four possible answers). The first answer immediately after the question is the correct answer.
- You may assume the quiz.csv file will always have a question followed by 4 answers and the first answer is the correct answer.
- However you should not assume and hardcode the total number of questions in your code. The marker may use different quiz.csv (which contains different number of questions) in marking your program.
Randomize the questions and randomize the answer choices
- You should not follow the question sequence given in the quiz.csv file
- You should not follow the answer sequence given in the quiz.csv file
- You should randomize both the questions and the options
below is the code i have done, can help me make this code simpler or shorter with comment provided? the programming language is python
import random
allQuestions=[] allQuestionsAndOptions={} options=[] question="" index=0 congratulation_phrases=["Good job!", "Awesome!", "Correct!"] alphabet= ["a", "b", "c", "d"] abcd={} score=0 correctAnswer=""
file=r"quiz.csv" with open(file,'r') as f: for line in f: if index%5==0: question=line.rstrip() allQuestions.append(question) else: options.append(line.rstrip()) if len(options)==4: allQuestionsAndOptions.update({question:options}) options=[] index+=1
random.shuffle(allQuestions)
for i in range(len(allQuestions)): print("Question "+ str(i+1)) print(allQuestions[i]) listOfQuestionsAndOptions=allQuestionsAndOptions.get(allQuestions[i]) correctAnswer=listOfQuestionsAndOptions[0] random.shuffle(listOfQuestionsAndOptions) for j in range(len(listOfQuestionsAndOptions)): abcd.update({listOfQuestionsAndOptions[j]:alphabet[j]}) print(alphabet[j]+". "+listOfQuestionsAndOptions[j]) answer=input() if answer==abcd[correctAnswer]: print(random.choice(congratulation_phrases)) score+=1 abcd={} else: print("Sorry, you selected a wrong option, the correct answer is "+abcd[correctAnswer]+"") abcd={} print() print("End of the quiz, your score is "+ str(round(float((score/len(allQuestions))*100),2)))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started