Menu

Python 373 Type Ctrl C Shell Executing Input Function Keyboardinterrupt Exception Raised E Q43884480

Python 3.7.3

If you type Ctrl-C while the shell is executing the input()function, a KeyboardInterrupt exception will be raised. Forexample:

>>> x = input()

Traceback (most recent call last):

File “<pyshell#0>”, line 1, in <module>

    x = input()

KeyboardInterrupt

>>>

Create a wrapper function safe_input() which works just like thefunction input() except that it returns nothing when an exceptionis raised.

>>> x = safe_input()    # TypingCtrl-C

>>>x                  # x is None

>>> x = safe_input()    # Typing 45

45

>>>x                  # x is 45

’45’

Expert Answer


Answer to Python 3.7.3 If you type Ctrl-C while the shell is executing the input() function, a KeyboardInterrupt exception will be…

OR