Home  >  Article  >  Backend Development  >  How to write input month and output the number of days in the month using python

How to write input month and output the number of days in the month using python

尚
Original
2019-07-05 10:07:3320966browse

How to write input month and output the number of days in the month using python

The calendar module can be used to calculate dates in Python.

The implementation code is as follows:

#!/usr/bin/python3
import calendar
year = input("请输入年份:")
month = input("请输入月份:")
year = int(year)
month = int(month)
monthRange = calendar.monthrange(year,month)
print("%d年%d月有%d天" % (year,month,monthRange[1]))

The effect is as follows:

How to write input month and output the number of days in the month using python

For more Python related technical articles, please visit Python Tutorial column to learn!

The above is the detailed content of How to write input month and output the number of days in the month using python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn