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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started