Question

In: Computer Science

Design and write a Python 3.8 program that gives and grades a math quiz. The quiz...

Design and write a Python 3.8 program that gives and grades a math quiz. The quiz will give 2 problems for each of the arithmetic operations: +, -, *, /, and %. First, two addition problems will be presented (one at a time) with random numbers between 1 and 20. Then two subtraction problems, multiplication, division and modulus. For division use // and do floor division; for example: for 10//3, the answer should be 3. For an example of the first problem: the program generates two random numbers (let's say num1 is 17 and num2 is 5), and prints out a statement of the problem as 17 + 5 =. The user will enter a correct answer or a wrong answer. If the answer is correct, a message will be printed and one will be added to the number of correct answers. Then the second addition problem is given and checked. Next, two subtraction problems will be given and checked, and so on.

Define a function for each of the 5 operations. Each function will display 2 problems (one at a time) to be solved. The call to each function should return the number of correct answers (0, 1, or 2). After calling all 5 functions in sequence, the main program will print out the total score of that quiz, and asks the user if he/she wants to take another quiz. The main program should keep calling the 5 functions in sequence as long as the user wants to take another quiz.

Insert a screenshot of the programs output

Solutions

Expert Solution

import random

def addition():
    score = 0

    # 2 questions so loop twice
    for i in range(2):
        # Find two random numbers
        a = random.randint(1,20)
        b = random.randint(1,20)

        print(a, "+",b,"=",end = " ")
        answer = int(input())
        # Check if answer is correct
        if(answer == a+b):
            print("The answer is correct")
            score+=1
        else:
            print("The answer is wrong")
        
    return score

def subtraction():
    score = 0

    for i in range(2):
        # Find two random numbers
        a = random.randint(1,20)
        b = random.randint(1,20)

        print(a, "-",b,"=",end = " ")
        answer = int(input())

        # Check if answer is correct
        if(answer == a-b):
            print("The answer is correct")
            score+=1
        else:
            print("The answer is wrong")
    # Return number of correct answers.
    return score

def multiplication():
    score = 0

    for i in range(2):
        a = random.randint(1,20)
        b = random.randint(1,20)

        print(a, "*",b,"=",end = " ")
        answer = int(input())

        if(answer == a*b):
            print("The answer is correct")
            score+=1
        else:
            print("The answer is wrong")
        
    return score

def division():
    score = 0

    for i in range(2):
        a = random.randint(1,20)
        b = random.randint(1,20)

        print(a, "/",b,"=",end = " ")
        answer = int(input())

        if(answer == a//b):
            print("The answer is correct")
            score+=1
        else:
            print("The answer is wrong")
        
    return score

def modulus():
    score = 0

    for i in range(2):
        a = random.randint(1,20)
        b = random.randint(1,20)

        print(a, "%",b,"=",end = " ")
        answer = int(input())

        if(answer == a%b):
            print("The answer is correct")
            score+=1
        else:
            print("The answer is wrong")
        
    return score


if __name__ == "__main__":

    while(True):

        total_score = 0
        total_score += addition()
        total_score += subtraction()
        total_score += multiplication()
        total_score += division()
        total_score += modulus()

        print("Your total score is", total_score,"out of 10")

        print("Do you want to attempt the quiz again? Enter Y/y for yes and N/n for no")

        attempt = input()
        attempt.upper()

        if(attempt == "N"):
            break
        






I would love to resolve any queries in the comments. Please consider dropping an upvote to help out a struggling college kid :)

Happy Coding !!


Related Solutions

Program a math quiz on Python Specifications: - The program should ask the user a question...
Program a math quiz on Python Specifications: - The program should ask the user a question and allow the student to enter the answer. If the answer is correct, a message of congratulations should be displayed. If the answer is incorrect, a message showing the correct answer should be displayed. - the program should use three functions, one function to generate addition questions, one for subtraction questions, and one for multiplication questions. - the program should store the questions and...
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
Use Python 3, please type. Write a Python 3 program which is an arithmetic quiz for...
Use Python 3, please type. Write a Python 3 program which is an arithmetic quiz for children. The program asks the user to calculate the multiplication of two numbers generated at random in your code. The numbers should be in the range 1 through 10. User input is shown in bold black font in the example below. You will need to use random numbers. You should type the recommended comments at the top of your code and include three test...
Write a python program to read from a file the names and grades of a class...
Write a python program to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a gradesInput() function that reads data from a file and stores it and returns it as a dictionary....
Write a java program (use value returning method) that gives simple math quizzes. The program should...
Write a java program (use value returning method) that gives simple math quizzes. The program should display two random integers from 1 to 100 that are to be added, such as:    47 + 29 The program allows the user to enter the answer. If the answer is correct, display “congratulations”. If the answer is incorrect, the program should show the correct answer. Your result should look like, for example:    47 + 29 Enter your answer: 1 Wrong, the right answer...
This is an exercise to design and write a Python program in good programming style for...
This is an exercise to design and write a Python program in good programming style for a simulation of stock price over a period of 100 days. In this exercise, you are asked to simulate the stock price starting at $100.00 for 100 days with a daily fluctuation based on the Normal Distribution with mean = 0.0 & sigma = 0.0125. The program will show the daily stock price, the 7-day minimum, the 7-day maximum, the 7-day average, and the...
Need a program in java that creates a random addition math quiz The program should ask...
Need a program in java that creates a random addition math quiz The program should ask the user to enter the following The smallest and largest positive numbers to be used when generating the questions - The total number of questions to be generated per quiz - The total number of the quiz's to create from then the program should generate a random math (Just addition) quiz from what the user entered
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
Write a python program. Grades are values between zero and 10 (both zero and 10 included),...
Write a python program. Grades are values between zero and 10 (both zero and 10 included), and are always rounded to the nearest half point. To translate grades to the American style, 8.5 to 10 become an “A,” 7.5 and 8 become a “B,” 6.5 and 7 become a “C,” 5.5 and 6 become a “D,” and other grades become an “F.” Implement this translation, whereby you ask the user for a grade, and then give the American translation. If...
Write a program in Python jupyter notebook for following: Part1: Course grade calculation: Course grades for...
Write a program in Python jupyter notebook for following: Part1: Course grade calculation: Course grades for CIS 1100 are calculated based on two assignments, a midterm exam, and a final exam. Here are the weights of these. Assignments 25% Midterm exam 35% Final exam 40% Ask the user for the scores they received for the two assignments, midterm exam, and the final exam. Then calculate and display their total weighted score they received for the course. Based on the weighted...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT