diff --git a/lab-02/problem-07.py b/lab-02/problem-07.py index 8a3b006..da6a000 100644 --- a/lab-02/problem-07.py +++ b/lab-02/problem-07.py @@ -1,2 +1,10 @@ # Write a Python program that prompts the user to input a number and handles a KeyboardInterrupt exception if the user -# cancels the input. \ No newline at end of file +# cancels the input. + +# Prompt user to input a number and try if the input is cancelled +try: + input('Enter a number: ') +# Handle the expected KeyboardInterrupt exception +except KeyboardInterrupt: + # Print termination message + print('Program terminated by user.') \ No newline at end of file