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 cut-and-paste it into the top of your a 3. py file:
def is_int (n) :
""" Returns True of n is an int, and False otherwise.True
> is_int ('5.6')
False
"""
try:
int (n)
return True
except ValueError:
return False
You don't need to worry about try/catch, other than to know it's how Python handles errors (such as not being able to convert a
string to an int).
Using is_int, write a function called ask_int1(prompt) 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 ask_int 1 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? 3.4
How old are you? 20
20
 Here's a Python function that checks if a variable can be

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!