Hi! I'm trying to program a monthly calendar.... but I can't get the weekdays for the nth day
of the year right... my problem is written further down in the code...
from time import *
class Calendar:
'''Skapar en kalender för varje månad'''
def __init__(self, year, month):
self.year = year
self.month = month
from time import *
class Calendar:
'''Skapar en kalender för varje månad'''
def __init__(self, year, month):
self.year = year
self.month = month
def leap_year(self, year):
'''Metod som tar reda på om året är ett skottår'''
if (year % 4 == 0) and not(year % 100 == 0)or (year % 400 == 0):
return year
else:
return None
def weekday(self, year, weekday):
'''Metod som tar fram veckodagen för varje dag.'''
d = weekday
if year:
d += (year-1900) * 365
for i in range(1900, year):
if self.leap_year(i):
d += 1
My problem starts here..
#d = the amount of days from year 1900 until chosen year. Now I want each of these days to be given a weekday number from 0-6...starting from day 1 year 1900 which is a monday
(weekdays[0]), until day d which is the last day of the chosen year.... How do i do this? I have tried some things here: But I know they don't really work..can someone please help me?!
for i in range(0, d):
if (i % 7 == 0)or (i == 0):
i -= i
while i < 7:
i += 1
w = weekdays[i-1]
return w
and if (i % 7 == 0) and (i >= (d-6)):
print weekdays[(d-i)]
#Mainprogram
months = ['januari', 'februari', 'mars', 'april', 'maj', 'juni', 'juli', 'augusti',\
'september', 'oktober', 'november', 'december']
weekdays = ['Må', 'Ti', 'On', 'To', 'Fr', 'Lö', 'Sö']
days = [31,28,31,30,31,30,31,31,30,31,30,31]
def write_calendar(days_until):
'''Skriver ut kalendern'''
def menu():
'''Skriver ut menyn samt anropar metoder och funktioner för respektive alternativ.'''
choice = None
while choice != '3':
print \
'''
(1) See this months calendar
(2) Choose year and month
(3) End
'''
choice = raw_input('Which alternative do you choose?')
if choice == '1':
today = localtime()
this_month = Calendar(today[0], today[1])
this_month.leap_year(today[0])
this_month.weekday(today[0], 0)
a = 0
for i in range(0, (today[1]-1)):
a += days[i]
elif choice =='2':
chosen_year = input(What year would you like to see?')
chosen_month = input(What month would you like to see?')
your_choice = Calendar(chosen_year, chosen_month)
your_choice.leap_year(chosen_year)
your_choice.weekday(chosen_year, 0)
a = 0
for i in range(0, (chosen_month-1)):
a += days[i]
menu()