Question: Python Program Create a trivia game in which players have a choice of categories to choose from. Make at least three categories. Each category of

Python Program

Create a trivia game in which players have a choice of categories to choose from. Make at least three categories. Each category of trivia questions should be in a separate text file. The file format for the text files is as follows:

Title of the Category

A quip about the next question.

The question

Possible answer 1

Possible answer 2

Possible answer 3

Possible answer 4

The correct answer number

Why that is the correct answer.

Points the question is worth

Repeat this format from the Quip about the next question - Points the question is worth for each question in that category. (The title should only be in the file once at the top.)

In the file that I provided you will find that some the questions have a forward slash (/) in the middle of the question. This is done on the questions that are long and need to be separated over two lines. Since the file format needs the entire question on one line, it is entered in the text file on one line and the forward slash is placed where you want the program to separate the line when the question is displayed to the player. So in your program after reading in the question from the file, you need to replace the forward slash (/) with a new line character before displaying it to the screen. In python the new line character is a back slash (\) followed by an n ( ).

Display the category choices to the player in a menu format and allow them to select a category. You may list the categories by hard coding them in the program, or you can get the titles from the files and use them to list the categories.

Once the player has made a selection, you will need to open the corresponding file and read all the information for the first question into the program to start the game. After each question, give the list of possible answers and allow the player to choose one. If they are correct, then display a message that states they are correct, the reason why, and add the points to their score. If they are wrong, then display a message that state they are wrong. Then display the correct answer and why it is the correct answer. Do not add the points to their score.

Then you will need to read all the information for the next question from the file and repeat the entire process until the end of the file has been reached.

When all the questions have been asked and answered, display a message that states that was the last question and display the player's total score. Then ask them if they would like to play again. If they say yes, then display the menu of category choices and allow them to choose another category.

Create 2 files of questions

Create 2 trivia files in the correct format to use in the game.

Creating a menu

Create a menu for the player to choose a category from. This can be done by either hard coding the category names in your program, or for extra bonus points, you can read the titles from the files and use the titles to create the menu. 10 points for hard coded menu 20 points for using the titles read in from the file to create the menu.

Reading in the question info

Correctly read in and store all the information about each question. You may want to use a list to store the 4 possible answers in as opposed to 4 separate variables.

Display the title of the category and the players name

Before the question round begins, display a welcome message using the title of the category and the player's name.

Displaying question info

Display the quip about the question, then the question, then each of the 4 possible answers along with a number for the user to choose an answer by. Then ask them what is the correct answer and read in their input. Example: On the Run with a Mammal. Let's say you turn state's evidence and need to "get on the lamb." If you wait too long, what will happen? 1. You'll end up on the sheep 2. You'll end up on the cow. 3. You'll end up on the goat. 4. You'll end up on the menu. Please choose the correct answer:

Testing player's answer

Once the player has entered their answer, you need to test this against the correct answer number read in from the file. Remember that the number read in from the file will come into the program as a string. If you do a readline, you will get the number and the end of line marker. This is not the same as the number 1 or even the string 1. You must read in the number from the file without the end of line marker. Then you will need to read past the end of line marker before reading the next line in the file. (Hint: use read(1) to get one character, then readline() to read past the end of line marker to get to the next line in the file)

Display results

If the player gets the answer correct, then display a message that states they are correct and the reason why. Then add the points to their total score. If the player gets the answer wrong, display a message stating they are wrong, what the correct answer was and why.

Play again?

After all of the questions have been asked. Inform the player that was the last question, display their total score, and ask them if they would like to play again. If they indicate they would like to play again, display the menu of category choices for them to choose from. Don't forget to close the current file.

Opening and closing files

If using the titles from the files to create the menu, you will have to open them to read in the title and then close them. After the user makes a choice from the menu, ensure that you are opening the correct file according to their choice. Don't forget to close the file after all the questions have been asked.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!