{"id":185443,"date":"2022-04-11T13:19:50","date_gmt":"2022-04-11T13:19:50","guid":{"rendered":"https:\/\/thestudycorp.com\/?p=185443"},"modified":"2022-04-11T13:55:59","modified_gmt":"2022-04-11T13:55:59","slug":"generating-calendar-in-python","status":"publish","type":"post","link":"https:\/\/studyinghq.com\/essay-examples\/nursing\/generating-calendar-in-python\/","title":{"rendered":"Generating Calendar in Python"},"content":{"rendered":"\n<p>This article provides a sample solution on <a href=\"https:\/\/studyinghq.com\/essay-examples\/generating-calendar-in-python\">Generating Calendar in Python Plus other Homework Solutions.<\/a><\/p>\n\n\n\n<p>Permalink: <a href=\"https:\/\/studyinghq.com\/essay-examples\/generating-calendar-in-python\">https:\/\/studyinghq.com\/essay-examples\/generating-calendar-in-python<\/a><\/p>\n\n\n\n<p>As you continue,<a href=\"https:\/\/studyinghq.com\/essay-examples\/\"> thestudycorp.com<\/a> has the top and most qualified writers to help with any of your assignments. All you need to do is&nbsp;<a href=\"\/order\">place an order&nbsp;<\/a>with us. (Generating Calendar in Python)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution<\/strong><\/h2>\n\n\n\n<p><strong>Homework 1:&nbsp; Generate Calendar<\/strong><\/p>\n\n\n\n<p>&nbsp;&lt;pre&gt;def calendar(n, s):<\/p>\n\n\n\n<p>#this will convert string value to a corresponding integer<\/p>\n\n\n\n<p>&nbsp;if s == &#8220;Su&#8221;:<\/p>\n\n\n\n<p>&nbsp;d = 0<\/p>\n\n\n\n<p>&nbsp;elif s == &#8220;Mo&#8221;:<\/p>\n\n\n\n<p>&nbsp;d = 1<\/p>\n\n\n\n<p>&nbsp;elif s == &#8220;Tu&#8221;:<\/p>\n\n\n\n<p>&nbsp;d = 2<\/p>\n\n\n\n<p>&nbsp;elif s == &#8220;We&#8221;:<\/p>\n\n\n\n<p>&nbsp;d = 3<\/p>\n\n\n\n<p>&nbsp;elif s == &#8220;Th&#8221;:<\/p>\n\n\n\n<p>&nbsp;d = 4<\/p>\n\n\n\n<p>&nbsp;elif s == &#8220;Fr&#8221;:<\/p>\n\n\n\n<p>&nbsp;d = 5<\/p>\n\n\n\n<p>&nbsp;elif s == &#8220;Sa&#8221;:<\/p>\n\n\n\n<p>&nbsp;d = 6<\/p>\n\n\n\n<p>&nbsp;print (&#8220;Su Mo Tu We Th Fr Sa&#8221;)<\/p>\n\n\n\n<p>&nbsp;for j in range(d):<\/p>\n\n\n\n<p>&nbsp;print (&#8221; &#8220;, end = &#8221; &#8220;),<\/p>\n\n\n\n<p>&nbsp;i = 1<\/p>\n\n\n\n<p>&nbsp;while i &lt;= n:<\/p>\n\n\n\n<p>&nbsp;if i &lt; 10:<\/p>\n\n\n\n<p>&nbsp;print (&#8220;&#8221;,i,end=&#8221; &#8220;),<\/p>\n\n\n\n<p>&nbsp;else:<\/p>\n\n\n\n<p>&nbsp;print(i,end=&#8221; &#8220;),<\/p>\n\n\n\n<p>&nbsp;if(i + d) % 7 == 0:<\/p>\n\n\n\n<p>&nbsp;print (&#8221; &#8220;)<\/p>\n\n\n\n<p>&nbsp;i = i + 1<\/p>\n\n\n\n<p>n = int(input(&#8220;Input the number of days in the month (28-31): &#8220;))<\/p>\n\n\n\n<p>s = input(&#8220;Input the starting day (Su=Sun, Mo=Mon,&#8230;): &#8220;)<\/p>\n\n\n\n<p>calendar(n,s)&lt;\/pre&gt;<\/p>\n\n\n\n<p><strong>1b) Year 2020 Calendar<\/strong><\/p>\n\n\n\n<p>&nbsp;# Program to display&nbsp; 2020 calendar and User to enter the specific month to display<\/p>\n\n\n\n<p># importing calendar module<\/p>\n\n\n\n<p>import calendar<\/p>\n\n\n\n<p>yy = 2020&nbsp; # year<\/p>\n\n\n\n<p># To take month input from the user<\/p>\n\n\n\n<p>&nbsp;mm= int(input(&#8220;Enter year: &#8220;))<\/p>\n\n\n\n<p># display the calendar<\/p>\n\n\n\n<p>print(calendar.month(yy, mm))<\/p>\n\n\n\n<p><strong>1c) A short program for January 2020 Calendar<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; # Program to display&nbsp; Jan 2020 calendar&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; # importing calendar module<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; import calendar<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; yy = 2020&nbsp; # year<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; mm = 1&nbsp;&nbsp;&nbsp; #month<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; # the header will be January 2020<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; print(calendar.month(yy, mm))<\/p>\n\n\n\n<p><strong>2, <\/strong><strong>loop over 30 days of September<\/strong><strong><\/strong><\/p>\n\n\n\n<p>&nbsp;def date_iter(year, month):<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; for i in range(1, calendar.monthlen(year, month) + 1):<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; yield date(year, month, i)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for d in date_iter(2020, 9):<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(d)<\/p>\n\n\n\n<p>As you continue,<a href=\"https:\/\/studyinghq.com\/essay-examples\/\"> thestudycorp.com<\/a> has the top and most qualified writers to help with any of your assignments. All you need to do is&nbsp;<a href=\"\/order\">place an order&nbsp;<\/a>with us. (Generating Calendar in Python)<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"\/order\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/privateessaywriters.com\/wp-content\/uploads\/2022\/01\/order-1024x334.jpg\" alt=\"Generating Calendar in Python\" class=\"wp-image-98670\" width=\"834\" height=\"271\" title=\"\"><\/a><figcaption>Generating Calendar in Python<\/figcaption><\/figure>\n\n\n\n<p>b) &nbsp;<strong>Genialize your calendar to 100 year<\/strong><\/p>\n\n\n\n<p>&nbsp;days = [&#8220;su&#8221;, &#8220;mo&#8221;, &#8220;tu&#8221;, &#8220;we&#8221;, &#8220;th&#8221;, &#8220;fr&#8221;, &#8220;sa&#8221;]<\/p>\n\n\n\n<p>months = [&#8220;January&#8221;, &#8220;February&#8221;, &#8220;March&#8221;, &#8220;April&#8221;, &#8220;May&#8221;,<\/p>\n\n\n\n<p>&#8220;June&#8221;, &#8220;July&#8221;, &#8220;August&#8221;, &#8220;September&#8221;, &#8220;October&#8221;, &#8220;November&#8221;, &#8220;December&#8221;]<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; old_length_s = 0<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length_current_month = 0<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; month_header = &#8220;&#8221;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; title = &#8220;&#8221;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data = dict()<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for year in range(startYear, endYear):<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = &#8220;|&#8221;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # data[year] = dict()<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for month in months:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; old_length_s = len(s)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; s += &#8221; &#8220;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; # data[year][month] = dict()<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; cal_data = subprocess.Popen(&#8220;cal &#8221; + str(month) +<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; &#8221; &#8221; + str(year),shell=True, stdout=subprocess.PIPE)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; week_loop = 0<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; for line in iter(cal_data.stdout.readline, b&#8221;&#8221;):<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; if week_loop &gt; 1: #this is after month name and day_names<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char_num = 0<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; day = 0<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; date = &#8220;&#8221;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for c in line:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; date += c<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if char_num &gt; 1: #every three characters<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char_num = 0<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if len(date.strip()) &gt; 0: #somefields are blank in each month&#8217;s first week<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # data[year][month][int(date)] = days[day]<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if days[day] is &#8220;su&#8221;:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if int(date) &lt; 10:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s += &#8221; * &#8220;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s += &#8221; *&nbsp; &#8220;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s += &#8221; &#8221; + str(date.strip()) + &#8221; &#8220;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; date = &#8220;&#8221;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; day += 1<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char_num += 1<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; week_loop += 1<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; # print len(s)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if month is &#8220;February&#8221; and len(s) is 223:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s += &#8221;&nbsp;&nbsp;&nbsp; &#8220;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s += &#8221; |&#8221;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; if first_year is True:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length_current_month = len(s) &#8211; old_length_s<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blankspace = (length_current_month\/2) &#8211; len(month)\/2<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if len(month)%2 is not 0:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; month_header += &#8221; &#8220;*blankspace + month + &#8221; &#8220;*(blankspace-1)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>As you continue,<a href=\"https:\/\/studyinghq.com\/essay-examples\/\"> thestudycorp.com<\/a> has the top and most qualified writers to help with any of your assignments. All you need to do is&nbsp;<a href=\"\/order\">place an order&nbsp;<\/a>with us. (Generating Calendar in Python)<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"\/order\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/privateessaywriters.com\/wp-content\/uploads\/2022\/01\/order-1024x334.jpg\" alt=\"Generating Calendar in Python\" class=\"wp-image-98670\" width=\"834\" height=\"271\" title=\"\"><\/a><figcaption>Generating Calendar in Python<\/figcaption><\/figure>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; month_header += &#8221; &#8220;*blankspace + month + &#8221; &#8220;*blankspace<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; if month is &#8220;June&#8221;:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; s += &#8220;|&nbsp; &#8221; + str(year) + &#8221;&nbsp; ||&#8221;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; month_header += &#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; actual_title = str(startYear) + &#8221; to &#8221; + str(endYear-1)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; title = &#8221; &#8220;*((len(s)-7)-(len(actual_title)\/2 -1 )) + actual_title<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # print s<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; if first_year is True:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first_year = False<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(title)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(&#8220;\\n&#8221;*5)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(month_header)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(&#8220;\\n&#8221;*3)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for c in s:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; if c is not &#8220;|&#8221;:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dividing_line += &#8220;-&#8220;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decade_divider += &#8220;=&#8221;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dividing_line += c<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decade_divider += c<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; if str(year)[-1] is &#8220;0&#8221;:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(decade_divider)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(&#8220;\\n&#8221;)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(decade_divider)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; print(dividing_line)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(&#8220;\\n&#8221;)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(s)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(&#8220;\\n&#8221;)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; print(dividing_line)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(&#8220;\\n&#8221;*2)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(&#8220;* = sunday&#8221;)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(&#8220;\\n&#8221;*2)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; writer.close()<\/p>\n\n\n\n<p>def Main():<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; print<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startYear = int(sys.argv[1])<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; year_interval = int(sys.argv[2])<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endYear = startYear + year_interval<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getDaysData(startYear, endYear)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-read-more-generating-calendar-in-python\"><strong>Read More:<\/strong> &#8211; Generating Calendar in Python<\/h2>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-the-study-corp wp-block-embed-the-study-corp\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/studyinghq.com\/essay-examples\/scholarly-activity-summary-clinical-nurses-seminar\/\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-the-study-corp wp-block-embed-the-study-corp\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/studyinghq.com\/essay-examples\/capstone-project-change-proposal-example\/\n<\/div><\/figure>\n\n\n\n<p><a href=\"https:\/\/studyinghq.com\/essay-examples\/category\/solved-essays\/\">All Solved Essays<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article provides a sample solution on Generating Calendar in Python Plus other Homework Solutions. Permalink: https:\/\/studyinghq.com\/essay-examples\/generating-calendar-in-python As you continue, thestudycorp.com has the top and most qualified writers to help with any of your assignments. All you need to do is&nbsp;place an order&nbsp;with us. (Generating Calendar in Python) Solution Homework 1:&nbsp; Generate Calendar &nbsp;&lt;pre&gt;def calendar(n, [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[21],"class_list":["post-185443","post","type-post","status-publish","format-standard","hentry","category-nursing","tag-solved-essays"],"_links":{"self":[{"href":"https:\/\/studyinghq.com\/essay-examples\/wp-json\/wp\/v2\/posts\/185443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/studyinghq.com\/essay-examples\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studyinghq.com\/essay-examples\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studyinghq.com\/essay-examples\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/studyinghq.com\/essay-examples\/wp-json\/wp\/v2\/comments?post=185443"}],"version-history":[{"count":0,"href":"https:\/\/studyinghq.com\/essay-examples\/wp-json\/wp\/v2\/posts\/185443\/revisions"}],"wp:attachment":[{"href":"https:\/\/studyinghq.com\/essay-examples\/wp-json\/wp\/v2\/media?parent=185443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studyinghq.com\/essay-examples\/wp-json\/wp\/v2\/categories?post=185443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studyinghq.com\/essay-examples\/wp-json\/wp\/v2\/tags?post=185443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}