Question

In: Computer Science

In this python program , you are to build a trivia game. The game should present...

In this python program , you are to build a trivia game. The game should present each question – either in order or randomly – to the player, and display up to four possible answers. The player is to input what they believe to be the correct answer.   The game will tell the player if they got it right or wrong and will display their score. If they got it right, their score will go up. If they got it wrong, their score will stay the same. After all the questions have been asked, the game will present the final score correct, the final score incorrect and allow the player to play again if they choose.

You have a lot of leeway in designing this game and you can use your book though there are minimum requirements. Develop your own code and try to use as many of these tools and techniques that you learned about in Chapters in your text. You may leverage other techniques in other Chapters that were not covered if you like, BUT you will need to add comments to the code with why you selected them and a brief description on how it works.

Your final script MUST include the following at a minimum:

  • Mainline logic
  • Double Strings
  • Error handling (Try/except/else/final)
  • Header
  • Comments
  • Global/Local Variables (Users name, counters, etc.)
  • At least 1 custom function
  • Use of List/Tuple/Dictionary
  • Use of at least 1 looping function (while/for)

You will be graded on your program design and how well you incorporated what you have learned.   If you get stuck or need some guidance, please feel free to ask.

To get you started, here are five, four-answer multiple-choice questions that you can use. The correct answers have been denoted with an asterisk. You may use your own questions if you like. When you “load” the questions into your program, you may re-write them however you need to.

How many computer-generated effects were used in the movie Lord of the Rings - Return of the King?

540

799

1205

*1488

               

In the movie "The Blues Brothers", what does Jake order at the diner?

A medium pizza with pineapple and ham

3 cheeseburgers with the works and a tall glass of milk

* 4 fried chickens and a Coke

A small Greek salad with extra feta, a steak (well done), 2 baked potatoes, and a coffee

In The Simpsons, what football team has Homer always wanted to own?

Washington Redskins

*Dallas Cowboys

Denver Broncos

Cleveland Browns

Solutions

Expert Solution

import sys


def askQuestionAnswer(question_list, answer_list):
    answers = []
    for count in range(len(question_list)):
        print('\nQuestion No : ' + str(count + 1))
        print(question_list[count] + '\n')
        for answer in range(len(answer_list[count])):
            print(str(answer) + ')\t' + str(answer_list[count][answer]))

        answers.append(int(input()))
    return answers


def main():
    player_name = input('Enter your name : ')
    """
        It will set all the questions, options, and correct answers.
        Once user will press 1, it will invoke askQuestionAnswer() and game will be started.
        In each question user has to type answer and that number will be stored in one list.
        Fially that list will be comprared with the correct_anwer list and check the number of correct answers. 
    """
    question_list = [
        'How many computer-generated effects were used in the movie Lord of the Rings - Return of the King?',
        'In the movie "The Blues Brothers", what does Jake order at the diner?',
        'In The Simpsons, what football team has Homer always wanted to own?']
    answer_list = [[540, 799, 1205, 1488],
                   ['A medium pizza with pineapple and ham', '3 cheeseburgers with the works and a tall glass of milk',
                    '4 fried chickens and a Coke'],
                   ['Washington Redskins', 'Dallas Cowboys', 'Denver Broncos', 'Cleveland Browns']]
    correct_answer = [3, 2, 1]
    print(player_name + '!!! Are you ready to play game? \nPress 1 to play game or 0 to quit game')
    choice = int(input())
    if choice == 1:
        answers = askQuestionAnswer(question_list, answer_list)
    elif choice == 0:
        sys.exit(0)
    right_answer = 0
    for i in range(len(answers)):
        if answers[i] == correct_answer[i]:
            right_answer += 1

    print(player_name+' Your Total Score is : ' + str(right_answer))


if __name__ == '__main__':
    main()

Please follow the coments and run the program.

I am attaching the screenshot for your better understanding.

If you still have any queries, please feel free to post in comment box. If you like my answer, then hit on like button, it really motivates us to provide a good quality answer.


Related Solutions

In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. Now...
In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. Now that you have successfully created Trivia objects, you will continue 6B by creating a linked list of trivia objects. Add the linked list code to the Trivia class. Your linked list code should include the following: a TriviaNode class with the attributes: 1. trivia game - Trivia object 2. next- TriviaNode 3. write the constructor, accessor, mutator and toString methods. A TriviaLinkedList Class which...
Explain this python program as if you were going to present it to a class in...
Explain this python program as if you were going to present it to a class in a power point presentation. How would you explain it? I am having a hard time with this. I have my outputs and code displayed throughout 9 slides. #Guess My Number Program # Python Code is modified to discard duplicate guesses by the computer import random #function for getting the user input on what they want to do. def menu(): #print the options print("\n\n1. You...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program accepts the lengths of three (3) sides of a triangle as input from a player. The program output should indicate whether the triangle is a right triangle, an acute triangle, or an obtuse triangle. 1.Tips to help you for this assignment: Make sure each side of the triangle is a positive integer. Use try/except for none positive integer input. 2. Validating the triangle. That...
Python: Trivia Questionaire Create a trivia application using the provided file which contains 15 questions in...
Python: Trivia Questionaire Create a trivia application using the provided file which contains 15 questions in it. Your application should randomly select how many questions will be presented to the user and it must be a number not greater than the number of questions in the file. Every question that is displayed should be randomly selected from the list and should be non-repetitive; in other words, you should not ask the same question twice. Your application should keep track of...
Write a program in Python to simulate a Craps game: 1. When you bet on the...
Write a program in Python to simulate a Craps game: 1. When you bet on the Pass Line, you win (double your money) if the FIRST roll (a pair of dice) is a 7 or 11, you lose if it is ”craps” (2, 3, or 12). Otherwise, if it is x ∈ {4, 5, 6, 8, 9, 10}, then your point x is established, and you win when that number is rolled again before ’7’ comes up. The game is...
Write a program in PYTHON for a (very) rudimentary shooter "game". You are the only shooter...
Write a program in PYTHON for a (very) rudimentary shooter "game". You are the only shooter and you start with ammo of 10. The one enemy doesn't shoot back and starts with health of 5. Code a custom function named shoot that prints "Shot fired" and returns True for a hit or False for a miss. Generate a random 0 to assign False or 1 to assign True. In the main function, use a while loop that runs the shoot function...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
The assignment is to build a program in Python that can take a string as input...
The assignment is to build a program in Python that can take a string as input and produce a “frequency list” of all of the wordsin the string (see the definition of a word below.)  For the purposes of this assignment, the input strings can be assumed not to contain escape characters (\n, \t, …) and to be readable with a single input() statement. When your program ends, it prints the list of words.  In the output, each line contains of a...
problem 3-1 You are going to build a C++ program which runs a single game of...
problem 3-1 You are going to build a C++ program which runs a single game of Rock, Paper, Scissors. Two players (a human player and a computer player) will compete and individually choose Rock, Paper, or Scissors. They will then simultaneously declare their choices and the winner is determined by comparing the players’ choices. Rock beats Scissors. Scissors beats Paper. Paper beats Rock. The learning objectives of this task is to help develop your understanding of abstract classes, inheritance, and...
Build a circuit for arcade game. You have 3 LEDS and 1 button. the LEDs should...
Build a circuit for arcade game. You have 3 LEDS and 1 button. the LEDs should recycle through 000,100,110,111,011, 001(back to 000). The user needs to hit the button during the 111 cycle 3 times in a row to win. The win is shown as an LED which is HIGH if the user won the last attempt of 3 presses. The win LED will be LOW otherwise
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT