In: Computer Science
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:
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
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.