﻿ Python Exercise: Convert month name to a number of days - w3resource

# Python Exercise: Convert month name to a number of days

## Python Conditional: Exercise - 33 with Solution

Write a Python program to convert month name to a number of days.

Sample Solution:

Python Code:

print("List of months: January, February, March, April, May, June, July, August, September, October, November, December")
month_name = input("Input the name of Month: ")

if month_name == "February":
print("No. of days: 28/29 days")
elif month_name in ("April", "June", "September", "November"):
print("No. of days: 30 days")
elif month_name in ("January", "March", "May", "July", "August", "October", "December"):
print("No. of days: 31 day")
else:
print("Wrong month name")

Sample Output:

List of months: January, February, March, April, May, June, July, August, September, October, November, Decemb
er
Input the name of Month: April
No. of days: 30 days

Flowchart :

## Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Returns a list with n elements removed from the beginning

Example:

def tips_take(itr, n = 1):
return itr[:n]
print(tips_take([1, 2, 3], 5))
print(tips_take([1, 2, 3], 0))

Output:

[1, 2, 3]
[]