Home > Backend Development > Python Tutorial > 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

Release: 2019-07-05 10:07:33
Original
21063 people have browsed it

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]))
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template