Question: Python Issue An IndexError exception exists when a sequence subscript is out of range. Write a function named getMonth() that takes a number between 1
Python Issue
An IndexError exception exists when a sequence subscript is out of range.
Write a function named getMonth() that takes a number between 1 and 12 as an argument and prints the three-character abbreviation of the corresponding month. You should use a try-except block to handle any exceptions that might occur.
For example, use a try-except statement which handles a possible IndexError if the number is out of range.
You also need to print an error message if the the number is invalid.
getMonth(1) | Jan |
getMonth(13) | ERROR: out of range! |
getMonth('a') | ERROR: invalid number! |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
