BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Program to Print Calendar

By Chaitanya Singh | Filed Under: Python Examples

We can use the built-in function month() of Calendar module to print a Calendar in Python. The function month() requires two arguments to display a Calendar of given month, first argument is the year in four digits format for example, 2003, 1997, 2018 etc. and second is the month in two digit format, for example 01, 04, 12 etc.

Program to print Calendar in Python

This program prompts the user to enter the year and month and based on the input it calls the month() function which displays the Calendar of the given month for a given year.

# Program published on https://beginnersbook.com
# Python program to print Calendar using
# Python built-in function

import calendar

# Enter in format - 2018, 1997, 2003 etc.
year = int(input("Enter Year: "))

# Enter in format - 01, 06, 12 etc.
month = int(input("Enter Month: "))

# printing Calendar
print(calendar.month(year, month))

Output:

Enter Year: 2018
Enter Month: 06
     June 2018
Mo Tu We Th Fr Sa Su
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30

Source Code in PyCharm IDE:
Python program to print Calendar

Related Python Examples:

  1. Python program to reverse a String using recursion
  2. Python program to check leap year
  3. Python program to check prime number
  4. Python program to add two matrices

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap