Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is using Python. Your submission should begin with the Trivia Challenge game from the textbook. You should have this working prior to attempting to

This is using Python.

Your submission should begin with the Trivia Challenge game from the textbook. You should have this working prior to attempting to modify for the instructions in the assignment. You are encouraged to download the working code from the course documents folder to compare to your efforts to build the code in the book.

Your submission MUST have variable points for each question, and they should be in the .txt file that the questions are located within. Think about scalability in other words if we wanted to expand this game to 20 questions, all that you should have to alter is the .txt file that the questions are located in.

You other challenge is to maintain a high score list and that MUST read and write to a file. I suggested in another announcement/email that it was probably easier to write that high scores to another text or data file. If you do so, that file MUST be included in your submission.

*Two of the files are below*

.txt file

An Episode You Can't Refuse 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? You'll end up on the sheep You'll end up on the cow You'll end up on the goat You'll end up on the emu 1 A lamb is just a young sheep. The Godfather Will Get Down With You Now Let's say you have an audience with the Godfather of Soul. How would it be /smart to address him? Mr. Richard Mr. Domino Mr. Brown Mr. Checker 3 James Brown is the Godfather of Soul. That's Gonna Cost Ya If you paid the Mob protection money in rupees, what business would you most /likely be insuring? Your tulip farm in Holland Your curry powder factory in India Your vodka distillery in Russian Your army knife warehouse in Switzerland 2 The Rupee is the standard monetary unit of India. Keeping It the Family If your mother's father's sister's son was in "The Family," how are you /related to the mob? By your first cousin once removed By your first cousin twice removed By your second cousin once removed By your second cousin twice removed 1 Your mother's father's sister is her aunt -- and her son is your /mother's first cousin. Since you and your mother are exactly one generation /apart, her first cousin is your first cousin once removed. A Maid Man If you were to literally launder your money, but didn't want the green in your /bills to run, what temperature should you use? Hot Warm Tepid Cold 4 According to my detergent bottle, cold is best for colors that might run.

.py file

# Trivia Challenge # Trivia game that reads a plain text file

import sys

def open_file(file_name, mode): """Open a file.""" try: the_file = open(file_name, mode) except IOError as e: print("Unable to open the file", file_name, "Ending program. ", e) input(" Press the enter key to exit.") sys.exit() else: return the_file

def next_line(the_file): """Return next line from the trivia file, formatted.""" line = the_file.readline() line = line.replace("/", " ") return line

def next_block(the_file): """Return the next block of data from the trivia file.""" category = next_line(the_file) question = next_line(the_file) answers = [] for i in range(4): answers.append(next_line(the_file)) correct = next_line(the_file) if correct: correct = correct[0] explanation = next_line(the_file)

return category, question, answers, correct, explanation

def welcome(title): """Welcome the player and get his/her name.""" print("\t\tWelcome to Trivia Challenge! ") print("\t\t", title, " ") def main(): trivia_file = open_file("trivia.txt", "r") title = next_line(trivia_file) welcome(title) score = 0

# get first block category, question, answers, correct, explanation = next_block(trivia_file) while category: # ask a question print(category) print(question) for i in range(4): print("\t", i + 1, "-", answers[i])

# get answer answer = input("What's your answer?: ")

# check answer if answer == correct: print(" Right!", end=" ") score += 1 else: print(" Wrong.", end=" ") print(explanation) print("Score:", score, " ")

# get next block category, question, answers, correct, explanation = next_block(trivia_file)

trivia_file.close()

print("That was the last question!") print("You're final score is", score) main() input(" Press the enter key to exit.")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

Students also viewed these Databases questions

Question

Be able to cite the advantages of arbitration

Answered: 1 week ago

Question

5. Arranging for the training facility and room.

Answered: 1 week ago

Question

1. Discuss the five types of learner outcomes.

Answered: 1 week ago