Question
This is for an intro to python class using Python 3: Write a program with a function called retrieve_integer. This function should ask the user
This is for an intro to python class using Python 3:
Write a program with a function called retrieve_integer. This function should ask the user for a number. If they enter a non-integer, your function should print "Uh oh!". However, the exception should not stop there; it should continue to wherever your function was called! (Consider using the word raise by itself here.)
use this at the end of your program:
try:
print(retrieve_integer())
except ValueError:
print('ValueError caught!')
Sample Input:
abc
Sample Output:
Enter number: Uh oh!
ValueError caught!
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