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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 5GZ
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage