Ask Question
23 January, 22:28

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. 23 January, 22:42
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers