Trivia Game In this programming exercise, you will create a simple trivia game for two players. The program will work like this:     Starting with player 1, each player gets a turn at answering 5 trivia questions. (There should be a total of 10 questions.) When a question is displayed, 4 possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point.     After answers have been selected for all the questions, the program displays the number of points earned by each player and declares the player with the highest number of points the winner. To create this program, write a Question class to hold the data for a trivia question. The Question class should have attributes for the following data:     A trivia question     Possible answer 1     Possible answer 2     Possible answer 3     Possible answer 4 The number of the correct answer (1, 2, 3, or 4) The Question class also should have an appropriate _ _init_ _ method, accessors, and mutators. The program should have a list or a dictionary containing 10 Question objects, one for each trivia question. Make up your own trivia questions on the subject or subjects of your choice for the objects. What I have so far is the class Question and a dictionary with questions (along with possible answers) as the key and values as the solution. I attached both my class and function below

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

9. Trivia Game

In this programming exercise, you will create a simple trivia game for two players. The program will work like this:

    Starting with player 1, each player gets a turn at answering 5 trivia questions. (There should be a total of 10 questions.) When a question is displayed, 4 possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point.

    After answers have been selected for all the questions, the program displays the number of points earned by each player and declares the player with the highest number of points the winner.

To create this program, write a Question class to hold the data for a trivia question. The Question class should have attributes for the following data:

  •     A trivia question
  •     Possible answer 1
  •     Possible answer 2
  •     Possible answer 3
  •     Possible answer 4
  • The number of the correct answer (1, 2, 3, or 4)

The Question class also should have an appropriate _ _init_ _ method, accessors, and mutators.

The program should have a list or a dictionary containing 10 Question objects, one for each trivia question. Make up your own trivia questions on the subject or subjects of your choice for the objects.

What I have so far is the class Question and a dictionary with questions (along with possible answers) as the key and values as the solution. I attached both my class and function below

import trivia
def questions():
prompts = {'What is Harry Potters middle name?\na)James\nb)Lilly\nc) Hagrid\nd)Alexander':'a',\
2
3
4.
'What is my middle name?\na)Croft\nb)Web\nc) Zane\nd) Lynn':'c',\
"What is CBC's mascot?\na) Bear\nb) Snake\nc) Fish\nd) Hawk":'d',\
'What class am I working on?\na)Math\nb) Python\nc)Windows Servers\nd)Eglish':'b',\
'How old am I(Kale)?\na)39\nb)40\nc) 26\nd)20':'c',\
'Who is the queen?\na) Beyonce\nb)Elizabeth\n\c)My Boyfriend\nd)Me':'a',\
8
9.
'What is today?\na)Tuesday\nb) Sunday\nc) Saturday\nd)Wednesday':'a',\
'In what month is my birthday (Kale)?\na) December\nb)March\nc)April\nd)May':'a',\
'In which book does Dumbledore die?\a)6th\nb)4th\nc)He does not\nd)1':'a',\
10
11
12
13
'How many drone strikes did Obama call during his presidency(true story)?\na)None\nb)A few\nc)As few as were needed\nd)563':'d'}
p1=0
p2=0
for line in prompts:
14
15
16
print(line)
answer=input('Answer: ')
17
18
19
20
21
print('Player 1 got:', p1, 'points.')
print('Player 2 got:', p2, 'points.')
questions ()
22
23
24
25
Transcribed Image Text:import trivia def questions(): prompts = {'What is Harry Potters middle name?\na)James\nb)Lilly\nc) Hagrid\nd)Alexander':'a',\ 2 3 4. 'What is my middle name?\na)Croft\nb)Web\nc) Zane\nd) Lynn':'c',\ "What is CBC's mascot?\na) Bear\nb) Snake\nc) Fish\nd) Hawk":'d',\ 'What class am I working on?\na)Math\nb) Python\nc)Windows Servers\nd)Eglish':'b',\ 'How old am I(Kale)?\na)39\nb)40\nc) 26\nd)20':'c',\ 'Who is the queen?\na) Beyonce\nb)Elizabeth\n\c)My Boyfriend\nd)Me':'a',\ 8 9. 'What is today?\na)Tuesday\nb) Sunday\nc) Saturday\nd)Wednesday':'a',\ 'In what month is my birthday (Kale)?\na) December\nb)March\nc)April\nd)May':'a',\ 'In which book does Dumbledore die?\a)6th\nb)4th\nc)He does not\nd)1':'a',\ 10 11 12 13 'How many drone strikes did Obama call during his presidency(true story)?\na)None\nb)A few\nc)As few as were needed\nd)563':'d'} p1=0 p2=0 for line in prompts: 14 15 16 print(line) answer=input('Answer: ') 17 18 19 20 21 print('Player 1 got:', p1, 'points.') print('Player 2 got:', p2, 'points.') questions () 22 23 24 25
e trivia.py > s Question
E
Elass Question:
def _init_(self,trivia,al, a2, a3, a4, sol):
self._trivia=trivia
self._al=al
2
4
self._a2=a2
self._a3=a3
self._a4=a4
6
7
self._sol=sol
def set_trivia (self,trivia):
self._trivia=trivia
def set_a1(self, a1):
self._al=a1
8
9
10
11
12
def set_a2(self,a2):
self._a2=a2
def set_a1(self, a3):
self._a3=a3
def set_a1(self,a4):
13
14
15
16
17
18
self._a4=a4
def get_trivia(self):
return self._trivia
def get_a1(self):
19
20
21
22
return self._a1
def get_a2(self):
return self._a2
def get_a3(self):
23
24
25
return self._a3
def get_a4(self):
return self._a4
def get_sol(self):
return self._sol
def _str_(self):
result= self.get_trivia+'\n'+\
'a)'+self.get_a1 +'\n'+\
26
27
28
29
30
31
32
33
34
'b)'+self.get_a2+' \n'+\
'c)'+self.get_a3+'\n',\
'd)'+self.get_a4
35
36
37
return result
def is_correct(self,sol):
return self._sol
38
D 39
Transcribed Image Text:e trivia.py > s Question E Elass Question: def _init_(self,trivia,al, a2, a3, a4, sol): self._trivia=trivia self._al=al 2 4 self._a2=a2 self._a3=a3 self._a4=a4 6 7 self._sol=sol def set_trivia (self,trivia): self._trivia=trivia def set_a1(self, a1): self._al=a1 8 9 10 11 12 def set_a2(self,a2): self._a2=a2 def set_a1(self, a3): self._a3=a3 def set_a1(self,a4): 13 14 15 16 17 18 self._a4=a4 def get_trivia(self): return self._trivia def get_a1(self): 19 20 21 22 return self._a1 def get_a2(self): return self._a2 def get_a3(self): 23 24 25 return self._a3 def get_a4(self): return self._a4 def get_sol(self): return self._sol def _str_(self): result= self.get_trivia+'\n'+\ 'a)'+self.get_a1 +'\n'+\ 26 27 28 29 30 31 32 33 34 'b)'+self.get_a2+' \n'+\ 'c)'+self.get_a3+'\n',\ 'd)'+self.get_a4 35 36 37 return result def is_correct(self,sol): return self._sol 38 D 39
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

In your function_question you try to append a built-in function to a list which is not possible

Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY