Question: Here's a Python function that checks if a variable can be converted to an int. Please cut - and - paste it into the top
Here's a Python function that checks if a variable can be converted to an int. Please cutandpaste it into the top of your a py file:
def isint :
Returns True of is an int, and False otherwise.True
isint
False
try:
int
return True
except ValueError:
return False
You don't need to worry about trycatch other than to know it's how Python handles errors such as not being able to convert a
string to an int
Using isint, write a function called askintprompt that prints the string prompt on the screen and then reads an int
typed by the user. If the user types an invalid int, then askint prints the prompt and asks again. It keeps asking until the user
enters a valid int.
For example:How old are you? ten
How old are you?
How old are you?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
