QuestionQuestion

Trivia Game

Info:
Trivia games are very popular with questions for each player. We are going to make a 2 player game with the questions and answers being stored in a class.

The Program Spec:

● Each question will have 4 possible answers. Each player will take turns with the questions. There will be a total of 10 questions, each player getting a chance to answer 5 of them. If the player selects the correct answer, they earn a point. Tell the player whether they got it right or wrong.

● 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. If there is a tie, announce that.

● Create a Question class to hold the data for a trivia question. The class should have the 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 should also have an appropriate __init__ method, accessors, mutators, and a __str__ method. Include a mutator and accessor for each member variable. Add other functions if you wish. The __init__ method should have the defaults('Default question', 'Default Answer 1', 'Default Answer 2', 'Default Answer 3', 'Default Answer 4', 1)

● Create a value-returning function named createQuestionsAnswers( ) that creates a list containing 10 question objects, one for each trivia question. Make
up your own trivia questions and answers on the subjects of your choice and hard code them in this function.

● The main() should call createQuestionsAnswers( ) and then use that returne list to display the question for each player in turn. Validate the user's choice to keep it between 1 and 4. Keep track of the number of correct answers and display the winner, or tie, at the end.

● Be sure to include comments in your code.

● Create a run and include it as output with your program. Be sure to show that the validation works for the possible answers.

Partial Sample output:
----------------------Output--------------------
>>>
Question for the first player:
How many days are in a lunar year?
1. 354 2. 365 3. 243
4. 379
Enter your solution (between 1 and 4): -8
Try again
Enter your solution (between 1 and 4): 8 Try again
Enter your solution (between 1 and 4): 1
That is the correct answer

Question for the second player:
What is the largest planet?
1. Mars
2. Jupiter
3. Earth
4. Pluto Enter your solution (between 1 and 4): 2
That is the correct answer
Question for the first player:
What is the largest kind of whale?
1. Orca whale
2. Humpback whale
3. Beluga whale
4. Blue whale
Enter your solution (between 1 and 4): 3
That is incorrect. The correct answer is 4
. . .
. . .
The first player earned 3 points
The second player earned 2 points
The first player wins the game

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

class Question:
    """Class to hold the data for a trivia question"""
    def __init__(self):
       self.question = 'Default question'
       self.answer_1 = 'Default Answer 1'
       self.answer_2 = 'Default Answer 2'
       self.answer_3 = 'Default Answer 3'
       self.answer_4 = 'Default Answer 4'
       self.correct_answer = 1
   
    def add_question(self, question):
       """mutator method that adds the question"""
       self.question = question
   
    def add_answers(self, answers):
       """mutator method that adds four possible answers"""
       self.answer_1, self.answer_2, self.answer_3, self.answer_4 = answers
   
    def add_correct_answer(self, correct_answer):
       """mutator method that adds one correct answer"""
       self.correct_answer = correct_answer...
$50.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats