Days in a Month

Write a Python program that takes a month number (from 1 to 12) as input and returns the number of days in that month. Assume it is not a leap year.

Example 1:

Input: 2

Output: 28

Example 2:

Input: 4

Output: 30

Use an if-else structure to match the input number to the month and return the number of days in that month.

def days_in_month(month_number):
    if month_number in [1, 3, 5, 7, 8, 10, 12]:
        return 30
    elif month_number == 2:
        return 28
    else:
        return 31

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!