Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import pickle
- 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.\n", e)
- input("\n\nPress the enter key to exit.")
- sys.exit()
- else:
- return the_file
- def next_line(the_file):
- line = the_file.readline()
- line = line.replace("/", "\n")
- return line
- def next_block(the_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)
- rating = next_line(the_file)
- return category, question, answers, correct, explanation, rating
- def welcome(title):
- """Welcome the player and get his/her name."""
- print("\t\tWelcome to Trivia Challenge!\n")
- print("\t\t", title, "\n")
- 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)
- category, question, answers, correct, explanation, rating = 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("\nRight!", end=" ")
- score += int(rating)
- else:
- print("\nWrong.", end=" ")
- print(explanation)
- print("Score:", score, "\n\n")
- # get next block
- category, question, answers, correct, explanation, rating = next_block(trivia_file)
- trivia_file.close()
- print("That was the last question!")
- print("You're final score is", score)
- name = input("Enter player name: ")
- records = {name: score}
- f = open("records.bin", "ab")
- pickle.dump(records, f)
- f.close()
- f = open("records.bin", "rb")
- high_scores = pickle.load(f)
- f.close()
- print(high_scores)
- main()
- input("\n\nPress the enter key to exit.")
- __________________________________________________
- # trivia.txt
- 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.
- 1
- 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.
- 2
- 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.
- 3
- 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.
- 4
- 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.
- 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement