Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

For-loop calendar help!

$
0
0
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

Code:




#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")


Viewing all articles
Browse latest Browse all 2485

Trending Articles