Ask 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 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.

+2
Answers (1)
  1. 29 June, 11:01
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers