Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE WRITE IN PYTHON and please try to add some explanation after each part Part 4 Write a function called check_answer which will determine if

PLEASE WRITE IN PYTHON

and please try to add some explanation after each part

Part 4

Write a function called "check_answer" which will determine if a given addition or subtraction problem was solved correctly. Here's the IPO notation for the function:

# function: check_answer # input: two numbers (number1 & number2, both integers); an answer (an integer) # and an operator (+ or -, expressed as a String) # processing: determines if the supplied expression is correct. for example, if the operator # is "+", number1 = 1, number2 = 2 and answer = 3 then the expression is correct # (1 + 2 = 3). # output: returns True if the expression is correct, False if it is not correct 

Here's a sample program that you can use to test your function:

answer1 = check_answer(1, 2, 3, "+") print (answer1) answer2 = check_answer(1, 2, -1, "-") print (answer2) answer3 = check_answer(9, 5, 3, "+") print (answer3) answer4 = check_answer(8, 2, 4, "-") print (answer4)

And here's the expected output:

True True False False

Part 5

Move all of your functions into an external module. This can be done by creating a new .py file in the same folder as your source code file. You can then "import" the functions from this file by using the following syntax:

import myfunctions

... assuming that the file you created is named "myfunctions.py". You can then call your functions in your main source code file using "dot syntax", like this:

myfunctions.check_answer(1,1,2,"+")

Part 6

Finally, put everything together and write a program that lets the user practice a series of random addition and subtraction problems. Begin by asking the user for a number of problems (only accept positive values) and a size for their numbers (only accept numbers between 5 and 20). The generate a series of random addition and subtraction problems - display the numbers to the user with your digital display functions. Then prompt the user for an answer and check the answer using your check_answer function. Your program should also keep track of how many correct questions the user answered during their game. Here's a sample running of the program:

How many problems would you like to attempt? -5 Invalid number, try again How many problems would you like to attempt? 5 How wide do you want your digits to be? 5-20: 3 Invalid width, try again How wide do you want your digits to be? 5-20: 5 Here we go! What is ..... ***** * ***** * ***** * * ***** * * * * * * * = 4 Correct! What is ..... ***** * ***** * ***** ***** ***** * * * * = -5 Correct! What is ..... * * * * * ***** ***** * ***** * ***** = 0 Sorry, that's not correct. What is ..... ***** * ***** * ***** * * ***** * * * * * * * = 3 Correct! What is ..... ***** * ***** * ***** * * ***** * * ***** * ***** * ***** = 4 Correct! You got 4 out of 5 correct!

Added features

Add multiplication problems to the game. You will have to update your check_answer function as well as add a new operator function to display the multiplication sign.

Add division problems to the game. You will have to update your check_answer function as well as add a new operator function to display the division sign. For division problems you need to ensure that the result of the problem you present is a whole number. For example, the following would be valid division problems for this game:

2 / 2 = 0 4 / 2 = 1 9 / 3 = 3

However, the following would NOT be valid since the answers are not whole numbers:

5 / 2 = 2.5 9 / 8 = 1.125 8 / 3 = 2.6666666 (repeating)

Ensure that the division problems you supply to your players always yield a whole number result. You may need to generate a few different numbers in order to do this (hint: while loop!).Add in a "drill" mode to your game. If this mode is activated by the user they will be re-prompted to solve a problem that they got incorrect. Points are turned off in "drill" mode since the user can attempt a problem multiple times. Here's an example:

How many problems would you like to attempt? 2 How wide do you want your digits to be? 5-10: 5 Would you like to activate 'drill' mode? yes or no: yes What is ..... ***** * * * * * * ***** * * ***** * * ***** * ***** * ***** = 1 Sorry, that's not correct. = 2 Sorry, that's not correct. = 3 Correct! What is ..... ***** * * ***** * * ***** * * ***** * * ***** * ***** * ***** = 13 Correct! Thanks for playing!

Keep track of statistics by problem type. For example, at the end of your program you could display a display like the following that summarizes the performance of the player:

Total addition problems presented: 5 Correct addition problems: 4 (80.0%) Total subtraction problems presented: 4 Correct subtraction problems: 3 (75.0%) No multiplication problems presented Total division problems presented: 1 Correct division problems: 0 (0.0%)

If you implemented "drill" mode you should modify your statistics display to include information about how many "extra" attempts it took so solve those problems. For example:

Total addition problems presented: 5 # of extra attempts needed: 0 (perfect!) Total subtraction problems presented: 4 # of extra attempts needed: 1 No multiplication problems presented Total division problems presented: 1 # of extra attempts needed: 5

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

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions