Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the base questions: Modify Listing 5.4, page 139, so it meets the following requirements: Like Listing 5.4, the new program shall present random

This is the base questions: Modify Listing 5.4, page 139, so it meets the following requirements:

Like Listing 5.4, the new program shall present random subtraction questions to the player until the player either (i) misses three questions in a row, or (iii) enters -1 to quit the game. Notice there is no maximum number of questions

The program shall keep track of the number of questions presented to the player, and the number of questions that were answered correctly.

At the end of the game the program shall:

Report the number of correct answers and the score. The score will be determined using the following expression: score = (questions answered correctly / total questions tried) * 100 Notice that if the user did not answer any questions, the score is zero.

Report whether the current score is the new highest score.

Ask the player whether s/he wants to play again. If the answer is N, the game ends. If the answer is Y, the game restarts.

This is the base program:

import random import time

correctcount = 0 #number of correct answers count = 0 #count the number of questions number_of_questions = float('inf') #constant starttime = time.time() #get start time end = eval(input("Enter -1 to stop or 0 to continue:"))

while count < number_of_questions: number1 = random.randint(0,9) number2 = random.randint(0,9) if number1 < number2: number1, number2 = number2, number1 answer = eval(input("what is" + str(number1) + "-" + str(number2) + "?")) if number1 - number2 == answer: print("You are correct!") correctcount += 1

else: print("Your answer is wrong. ", number1, "-", number2, "is", number1 - number2) count += 1

endtime = time.time() testtime = int(endtime - starttime) print("Your score is", (correctcount/number_of_questions)*100) #counts the amount of correct answers and divides by the number of questions then multiplies by 100 to get score for the game. print("Correct count is", correctcount, "out of", number_of_questions, " test time is", testtime, "seconds")

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

Why is it expensive for a firm to grow?

Answered: 1 week ago