Hi,
Am a beginner in python. Wrote this program based on the doomsday algorithm to calculate what day of the week corresponds to an inputted date.... at the moment idle rejects the program citing'march4 is not defined'.(line 23) Am i not clearly defining it there??

Program text:
#Doomsday Algorithm
#A program which calculates the day of the week corresponding to a user inputted numerical date,
#between the years 1900-2099.

import string

#Get the Date;

dateStr=raw_input("Please input a date (dd/mm/yyyy):")

#Split into Components;

dayStr, monthStr, yearStr = string.split(dateStr, "/")

if [int(yearStr)] >= 2000 :
y = (float(yearStr)-2000)
doomsday = 3 + ((y)/12) + ((y)%12) + ((y)%12/4)%7

z = float(yearStr[2:4])
if z%4 == 0 :
doomsday + 3 == march4
else:
doomsday + 4 == march4

if [int(monthStr)] == 1 :
x = abs([int(dayStr)-(31 + doomsday)])
elif [int(monthStr)] == 2 :
x = abs([int(dayStr)-doomsday])
elif [int(monthStr)] == 4 :
x = abs([int(dayStr)-4])
elif [int(monthStr)] == 5 :
x = abs([int(dayStr)-35])
elif [int(monthStr)] == 6 :
x = abs([int(dayStr)-36])
elif [int(monthStr)] == 7 :
x = abs([int(dayStr)-66])
elif [int(monthStr)] == 8 :
x = abs([int(dayStr)-97])
elif [int(monthStr)] == 9 :
x = abs([int(dayStr)-107])
elif [int(monthStr)] == 10 :
x = abs([int(dayStr)-138])
elif [int(monthStr)] == 11 :
x = abs([int(dayStr)-168])
elif [int(monthStr)] == 12 :
x = abs([int(dayStr)-199])

if x < 7:
distance == x
elif x == 7:
distance == 0
elif x > 7:
distance == 7%x

else :
y= (float(yearStr)-1900)
doomsday = 4 + (abs(y)/12) + (y%12) + (y%12/4)%7

z= float(yearStr[2:4])
if z%4 == 0 :
doomsday + 3 == march4

else:
doomsday + 4 == march4

if [int(monthStr)] == 1 :
x = abs([int(dayStr)-(31 + doomsday)])
elif [int(monthStr)] == 2 :
x = abs([int(dayStr)-doomsday])
elif [int(monthStr)] == 4 :
x = abs([int(dayStr)-4])
elif [int(monthStr)] == 5 :
x = abs([int(dayStr)-35])
elif [int(monthStr)] == 6 :
x = abs([int(dayStr)-36])
elif [int(monthStr)] == 7 :
x = abs([int(dayStr)-66])
elif [int(monthStr)] == 8 :
x = abs([int(dayStr)-97])
elif [int(monthStr)] == 9 :
x = abs([int(dayStr)-107])
elif [int(monthStr)] == 10 :
x = abs([int(dayStr)-138])
elif [int(monthStr)] == 11 :
x = abs([int(dayStr)-168])
elif [int(monthStr)] == 12 :
x = abs([int(dayStr)-199])

if x < 7:
distance == x
elif x == 7:
distance == 0
elif x > 7:
distance == 7%x

day = distance + march4

days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

dayStr = days[int(day)]

print "The day corresponding to the date," ,dateStr, "is:", dayStr

2
Contributors
5
Replies
7
Views
9 Years
Discussion Span
Last Post by sillyboy

I don't see you defining "march4" at all, it needs to have some value to be comparable.

what about (line 23)? it is equal to the value of doomsday(defined) + 3?? Sorry again for my annoying level of inexperience!!

doomsday + 3 == march4

I am not even sure this line is valid, but "march4" means nothing here. It has no value, the program isn't able to "guess" what "march4" is supposed to be.

any suggestions how I might modify this?

I have a feeling you are trying to get solutions the easy way, I don't completely understand the program you are creating, and unfortunately I don't really want to. You should give it more of a think, not just seeking solutions.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.