Method main: Print the message "Math Quiz". Call method display_menu and assign the return value which is the difficulty level, to a variable. Initialize a variable that will hold the number of correct answers given by the user to 0 (zero). Write a for-loop that will iterate three times. Inside this for-loop block is the following code: Call method generate_random passing it the difficulty level and assign the return value which is a random integer to a variable. This is the first number. Call method generate_random again passing it the difficulty level and assign the return value which is a random integer to a second variable. This is the second number. Print the message "Please calculate the following:". Prompt the user for what number1 plus number2 is, gather the user's response (answer) as an int and assign it to a variable. Write an if-statement that determines if the user's response is the correct answer of number1 plus number2. If so, increment the correct answer count variable. Print the difficulty level and the number of correct answers. Method display_menu: This method does not receive any parameters. It returns the difficulty level as an integer. Initialize any necessary variables for the following loop. Write a user input validation loop that does the following: Print the menu as follows: "Difficulty Levels are:" "1 - Easy" "2 = Intermediate" "3 = Hard" Prompt the user for the difficulty level, gather the user's response (answer) as an int and assign it to a variable. Write an if-statement that checks if the user entered 1, 2 or 3. If they did not, then print the following message "Please enter a difficulty level 1, 2 or 3", loop and prompt the user again until a valid response is entered. Return the user's response which is the integer representing the difficulty level. This return value is the difficulty level that is assigned to a variable in the main method. Method generate_random: This method receives the difficulty level as an integer parameter. It returns a random integer. Write an if-elif-else statement that checks if the difficulty level is 1 (one). If so, then generate a random integer between 1 (one) and 9 (nine) inclusive. Else if the difficulty level is 2 (two), then generate a random integer between 10 (ten) and 99 (ninety-nine) inclusive. Else generate a random integer between 100 (one hundred) and 999. Return the random integer. This return value is assigned to the number1 and number2 variables in the main method. Call the main method.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I'm trying to create this menu-driven modular program in python. I'm quite inexperienced with python and would appcreciate the assistance in creating it!

Both images attached contain information on how it should be done. One being pseudo code and the other being a sample output.

Thank you!

Method main:
Print the message "Math Quiz".
Call method display_menu and assign the return value which is the difficulty level, to a variable.
Initialize a variable that will hold the number of correct answers given by the user to 0 (zero).
Write a for-loop that will iterate three times. Inside this for-loop block is the following code:
Call method generate_random passing it the difficulty level and assign the return value which is a
random integer to a variable. This is the first number.
Call method generate_random again passing it the difficulty level and assign the return value which
is a random integer to a second variable. This is the second number.
Print the message "Please calculate the following:".
Prompt the user for what number1 plus number2 is, gather the user's response (answer) as an int
and assign it to a variable.
Write an if-statement that determines if the user's response is the correct answer of
number1 plus number2. If so, increment the correct answer count variable.
Print the difficulty level and the number of correct answers.
Method display_menu:
This method does not receive any parameters. It returns the difficulty level as an integer.
Initialize any necessary variables for the following loop.
Write a user input validation loop that does the following:
Print the menu as follows:
"Difficulty Levels are:"
"1 = Easy"
"2 = Intermediate"
"3 = Hard"
Prompt the user for the difficulty level, gather the user's response (answer) as an int
and assign it to a variable.
Write an if-statement that checks if the user entered 1, 2 or 3. If they did not, then
print the following message "Please enter a difficulty level 1, 2 or 3", loop and
prompt the user again until a valid response is entered.
Return the user's response which is the integer representing the difficulty level. This return
value is the difficulty level that is assigned to a variable in the main method.
Method generate_random:
This method receives the difficulty level as an integer parameter. It returns a random integer.
Write an if-elif-else statement that checks if the difficulty level is 1 (one). If so, then
generate a random integer between 1 (one) and 9 (nine) inclusive. Else if the difficulty
level is 2 (two), then generate a random integer between 10 (ten) and 99 (ninety-nine)
inclusive. Else generate a random integer between 100 (one hundred) and 999.
Return the random integer. This return value is assigned to the number1 and number2 variables
in the main method.
Call the main method.
Transcribed Image Text:Method main: Print the message "Math Quiz". Call method display_menu and assign the return value which is the difficulty level, to a variable. Initialize a variable that will hold the number of correct answers given by the user to 0 (zero). Write a for-loop that will iterate three times. Inside this for-loop block is the following code: Call method generate_random passing it the difficulty level and assign the return value which is a random integer to a variable. This is the first number. Call method generate_random again passing it the difficulty level and assign the return value which is a random integer to a second variable. This is the second number. Print the message "Please calculate the following:". Prompt the user for what number1 plus number2 is, gather the user's response (answer) as an int and assign it to a variable. Write an if-statement that determines if the user's response is the correct answer of number1 plus number2. If so, increment the correct answer count variable. Print the difficulty level and the number of correct answers. Method display_menu: This method does not receive any parameters. It returns the difficulty level as an integer. Initialize any necessary variables for the following loop. Write a user input validation loop that does the following: Print the menu as follows: "Difficulty Levels are:" "1 = Easy" "2 = Intermediate" "3 = Hard" Prompt the user for the difficulty level, gather the user's response (answer) as an int and assign it to a variable. Write an if-statement that checks if the user entered 1, 2 or 3. If they did not, then print the following message "Please enter a difficulty level 1, 2 or 3", loop and prompt the user again until a valid response is entered. Return the user's response which is the integer representing the difficulty level. This return value is the difficulty level that is assigned to a variable in the main method. Method generate_random: This method receives the difficulty level as an integer parameter. It returns a random integer. Write an if-elif-else statement that checks if the difficulty level is 1 (one). If so, then generate a random integer between 1 (one) and 9 (nine) inclusive. Else if the difficulty level is 2 (two), then generate a random integer between 10 (ten) and 99 (ninety-nine) inclusive. Else generate a random integer between 100 (one hundred) and 999. Return the random integer. This return value is assigned to the number1 and number2 variables in the main method. Call the main method.
Here is a sample output from a run of the program:
Math Quiz
Difficulty Levels are:
1= Easy
2 = Intermediate
3 = Hard
Enter the number for the difficulty level: 1
Please calculate the following:
What is 4 + 8? 12
Please calculate the following:
What is 2 + 4? 6
Please calculate the following:
What is 7 + 7? 14
The difficulty level was 1 and 3 was/were answered correctly.
Transcribed Image Text:Here is a sample output from a run of the program: Math Quiz Difficulty Levels are: 1= Easy 2 = Intermediate 3 = Hard Enter the number for the difficulty level: 1 Please calculate the following: What is 4 + 8? 12 Please calculate the following: What is 2 + 4? 6 Please calculate the following: What is 7 + 7? 14 The difficulty level was 1 and 3 was/were answered correctly.
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education