For-loop calendar help!

1447
2
02-18-2014 02:41 PM
sameryoussef
New Contributor
sorry about how messy it is but I cant figure out a way to get the for-loop to work, everything is working but the the for-loop

I am trying to print out the calendar

 


#Define number of days in a month and put in a list.
days_array= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

#Define month names
month_array= ['January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December']

#Get user input until they choose to quit
while True:
 #prompt for month
 month_input= int(input("\nEnter the month (1-12): "))
 if(month_input==0):
  break
 #prompt for year
 year_input= int(input("\nEnter the year (after 1900): "))
 if(year_input>1900) :
  break
 #Determine what day January of this year starts
 #follow formula
 starting_day_of_year= int(((year-1901) + (year-1901)/4+2)%7) 
 #determine what day current month starts
 #align month with index
 month_input= month_input-1
 starting_day_of_month= int((starting_day_of_year + sum(days_array[0: month_input]))%7)
 #adjust for March-December of leap year
 if (month_input >=2 & year%4== 0):
  starting_day_of_month= int((starting_day_of_month +1)%7)
 #print month, name & date
 #for-loop print each date of the month        



 NEED HELP HERE     
 

for i in range(days_array)(month_array)
 r just (4), end = "")
 #print Feb 29th if necessary
 
 if (month_input== 1 & year%4==0 ):
  print ("  29")

Tags (2)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus
Could you elaborate as to what this has to do with any of the Arc* platforms???
0 Kudos
XanderBakker
Esri Esteemed Contributor
Although I don't think this has anything to do with arcpy / ArcGIS, there is a module you could load called calendar:

import calendar
print calendar.month(2014,2)


results in:

   February 2014
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

sorry, but the formatting changes the output. So I added an image:
[ATTACH=CONFIG]31572[/ATTACH]


See for more functionality:
http://docs.python.org/2.7/library/calendar.html?highlight=calendar#calendar

Kind regards,

Xander
0 Kudos