Question: Using Python : Function get_integer(maximum,prompt) [2 points autograded] Use the Design Recipe to define a function get_integer(maximu m, prompt ) which consumes an int and

Using Python :

Function get_integer(maximum,prompt) [2 points autograded]

Use the Design Recipe to define a function get_integer(maximum,prompt) which consumes an int and a string and returns an integer. This function keeps asking the user to enter values using the prompt as the input message to the user until they enter one which can be interpreted as an integer between 0 and the argument to maximum. If they enter any character other than digits, or any integer outside the allowed range, keep asking until an acceptable value is obtained. If maximum <0, any (non-negative) integer should be accepted. Include a docstring!

Note: consider using the "isdigit()" string method.

For example:

Test
Input
Result
print(get_integer(100))
 

7w7 91 17

91

------------------------------------------------------------------------------------------------------

Function is_float(s) [2 points autograded]

Use the Design Recipe to define a function is_float(s) that consumes a string argument and returns True if the string can be turned into a float, and returns Falseotherwise. The string must contain only digits (at least one), (optionally) a single decimal, and (optionally) a leading - (if a negative value is desired). Otherwise, return False. Include a docstring!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!