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

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...
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...
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 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 python program that will be performing: - Read a CSV file 'annual.csv' enterprise into...
build a python program that will be performing: - Read a CSV file 'annual.csv' enterprise into a data structure - Count the number of rows and columns - Determine if the data contains empty values - Replace the empty values by 'NA' for strings, '0' for decimals and '0.0' for floats - Transform all Upper case characters to Lower case characters - Transform all Lower case characters to Upper case characters - save back the 'repaired' array as csv -...
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
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
It is time to play X-O. You should complete the program for this game. Part of...
It is time to play X-O. You should complete the program for this game. Part of this program is provided to you in two files: d4q2.py (it is complete, no need to be modified) and d4q2Lib.py (you have to complete). The annex has examples of messages displayed during the game. 1) The main program controls the game. a. It asks the user to start a game : if the response is not o or O, the program ends; If the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT