Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import random allQuestions=[] allQuestionsAndOptions={} options=[] question= index=0 congratulation_phrases=[Good job!, Awesome!, Correct!] alphabet= [a, b, c, d] abcd={} score=0 correctAnswer= file=rquiz.csv with open(file,'r') as f: for

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)))

Hi, I need help with changing the code for these to a simpler and shorter one. However, the output will still be the same! Please write #comments between each code for me to understand too! a good review will be given if answered correctly! I have been asking this question a few times and the answer are not of any help to me! it's python by the way and thanks in advance!

THIS IS THE QN!! 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Question Can employees make contributions to a profit sharing plan?

Answered: 1 week ago