Question
Write a function num_month that takes an integer in the range of 1 through 12 called month_int as a parameter and returns a string representing
Write a function num_month that takes an integer in the range of 1 through 12 called month_int as a parameter and returns a string representing the corresponding month of the year, where 1=January, 2 =February, 3=March and so on. The function should return an error message Invalid month number if the parameter is outside the range of 1 through 12. You may assume that the parameter will be only numbers.
I wrote my code like this:
def num_month(month_int):
if month_int < 1 and month_int > 12:
print('Invalid month number')
if month_int == 1:
print('The month 1 is: January.')
elif month_int == 2:
print('The month 2 is: February.')
elif month_int == 3:
print('The month 3 is: March.')
elif month_int == 4:
print('The month 4 is: Apri.l')
elif month_int == 5:
print('The month 5 is: May.')
elif month_int == 6:
print('The month 6 is: June.')
elif month_int == 7:
print('The month 7 is: July')
elif month_int == 8:
print('The month 8 is: August.')
elif month_int == 9:
print('The month 9 is: September.')
elif month_int == 10:
print('The month 10 is: July.')
elif month_int == 11:
print('The month 11 is: November.')
else: month_int == 12:
print('The month 12 is: December.')
return
but I get an error
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started