Creating a calendar in Python without using “import Calendar”

<pre>def calendar(n, s):
#this will convert string value to a corresponding integer
 if s == "Su":
 d = 0
 elif s == "Mo":
 d = 1
 elif s == "Tu":
 d = 2
 elif s == "We":
 d = 3
 elif s == "Th":
 d = 4
 elif s == "Fr":
 d = 5
 elif s == "Sa":
 d = 6 

 print ("Su Mo Tu We Th Fr Sa")
 for j in range(d):
 print (" ", end = " "),
 i = 1
 while i <= n:
 if i < 10:
 print ("",i,end=" "),
 else:
 print(i,end=" "),
 if(i + d) % 7 == 0:
 print (" ")
 i = i + 1 

n = int(input("Input the number of days in the month (28-31): "))
s = input("Input the starting day (Su=Sun, Mo=Mon,...): ")
calendar(n,s)</pre>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: