Ask Question
20 March, 17:14

The function below tries to read a whole number (i. e., an integer) from the user and return it as an integer to its caller. This works great as long as what the the user types is a whole number. If the user types a non-integer number of a collection of letters, this code will fail when it tries to convert it to an integer. Fix this code so that it returns None instead of raising an exception. Do this with try/except blocks.

+4
Answers (1)
  1. 20 March, 19:44
    0
    See explaination

    Explanation:

    def get_an_input_integer ():

    in_string = input ('Enter your favorite whole number:/n')

    try:

    in_integer = int (in_string)

    return in_integer

    except:

    return None
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “The function below tries to read a whole number (i. e., an integer) from the user and return it as an integer to its caller. This works ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers