Question

Python please Create a menu-driven modular program so user can take a 10-question math quiz, Addition...

Python please

Create a menu-driven modular program so user can take a 10-question math quiz, Addition or subtraction, at specified difficulty level. Easy(1-digit), Intermediate(2-digit), and Hard(3-digit). After a quiz, display the quiz type and level, and number of correct questions user answered.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:--

GIVEN THAT:--

  • Python Code:

    import random
    # a funtion to get a random number in a range
    def random_generator(low,high):
    r = random.randint(low,high)
    return r;
      
    # this funtion checks the answers with expected results and return score of a user
    def score(expected, answered):
    count=0
    for i in range(0,len(answered)):
    if expected[i]==answered[i]:
    count += 1
    return count

    def main():
    print("Welcome to math quiz");
    quiz_type = ['Subtraction', 'Addition']
    quiz_level = ['Easy', 'Intermediate', 'Hard']
    while(True):
    type = int(input("Select quiz type\n1.Subtraction\n2.Addition\n"))
    level = int(input("Select difficulty level\n1.Easy\n2.Intermediate\n3.Hard\n"))
    # based on difficulty level set the range of numbers
    high = 10**level-1
    low = 10**(level-1)-1
    expected = []
    answered = []
    if type == 1:
    # provide ten subtraction questions
    for i in range(0,10):
    # get random numbers
    x = random_generator(low,high)
    y = random_generator(low,high)
    # get the user answer.
    ans = int(input(str(x)+ " - " + str(y)+" = "))
    answered.append(ans)
    expected.append(x-y)
    else:
    # provide ten addition questions
    for i in range(0,10):
    # get random numbers
    x = random_generator(low,high)
    y = random_generator(low,high)
    # get the user answer.
    ans = int(input(str(x)+ " + " + str(y)+" = "))
    answered.append(ans)
    expected.append(x+y)
    # display the details
    print("quiz type: ",quiz_type[type-1])
    print("quiz level: ",quiz_level[level-1])
    total_score = score(expected, answered)
    print("You score:",total_score)
    choice = int(input("Enter 1 to play again: "))
    if(choice!=1):
    break
    main()
      

    Code ScreenShot:

    1 2 3 import random # a funtion to get a random number in a range def random generator(low, high): r = random.randint(low, hiif type == 1: # provide ten subtraction questions for i in range(0,10): # get random numbers x = random_generator (low, high)

    Sample output:C:\Users\Ankit Kumar\Desktop>python a.py Welcome to math quiz Select quiz type 1. Subtraction 2. Addition Select difficulty l

Add a comment
Know the answer?
Add Answer to:
Python please Create a menu-driven modular program so user can take a 10-question math quiz, Addition...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the...

    (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...

  • Design program so that it correctly meets the program specifications given below.   Specifications: Create a menu-driven...

    Design program so that it correctly meets the program specifications given below.   Specifications: Create a menu-driven program that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- square 2 -- circle 3 -- right triangle 4 -- quit If the user selects choice 1, the program should find the area of a square. If the user selects choice 2, the program should find the area of a circle. If the user...

  • This week we looked at an example math program that would display the answer to a...

    This week we looked at an example math program that would display the answer to a random math problem. Enhance this assignment to prompt the user to enter the solution to the displayed problem. After the user has entered their answer, the program should display a message indicating if the answer is correct or incorrect. If the answer is incorrect, it should display the correct answer. The division section should use Real data types instead of Integer data types. Keep...

  • [Using Python] Create a program to generate one random question, from a list of 5, for...

    [Using Python] Create a program to generate one random question, from a list of 5, for each repeated run. Report the number of the correct answers after all five questions have been answered. Your 5 questions should be a simple math problem, like "what is 5-4?" use a while loop based on the number of questions use a counter variable to count the number of questions asked e.g. questionCount +=1 user a counter variable to keep track of the correct...

  • Instructions Basically, you will modify the mathq program to make it satisfy a different set of...

    Instructions Basically, you will modify the mathq program to make it satisfy a different set of requirements, and fix what is not working in it. Specifically, imagine that the client for whom we created the mathq program for would now like some changes. To be exact: Part 1: They want it to provide addition and subtraction problems as well as multiplication and division. They still want the choice to be random, as before, but now the problem is randomly multiplication,...

  • Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type...

    Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type of credit card he/she would like to find the checksum for. 2. Based on the user's choice of credit card, asks the user for the n digits of the credit card. [Get the input as a string; it's easier to work with the string, so don't convert to an integer.] 3. Using the user's input of the n digits, finds the last digit of...

  • In the original flashcard problem, a user can ask the program to show an entry picked...

    In the original flashcard problem, a user can ask the program to show an entry picked randomly from a glossary. When the user presses return, the program shows the definition corresponding to that entry. The user is then given the option of seeing another entry or quitting. A sample session might run as follows: Enter s to show a flashcard and q to quit: s Define: word1 Press return to see the definition definition1 Enter s to show a flashcard...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas...

    I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked,...

  • python program sample output Problem 3 (Taking User Input) Write a function called userGuess(n) that takes...

    python program sample output Problem 3 (Taking User Input) Write a function called userGuess(n) that takes an integer n as an argument. This function should display n to the user and prompt them to enter the number num that is the largest power of 2 less than or equal to n. Have your function return the user's input num (it will be used in the next problem) Problem 4 (Making a Game) Finally, create a main() function for your program....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT