The assignment was to list only leap years. I didn't do a "perfect" program for her, because I didn't want to do her assignment FOR her. She had to make a function of this, so I didn't do that for her. And I left her the problem of trying to figure out how to have that zero year without just dropping it into the list. But I figured this would get her head around making lists and sorting data, so it couldn't hurt too much. Besides, it was fun to program for a few minutes. I haven't done much programming since I've been in Croatia.
So, this time, instead of getting the Croatian language, you get the Python language:
#!/usr/bin/python
#written by matt hollingsworth
#04.04.2007
#short script to count every four years and print the year out
#evidently leap years don't land right ON the century mark, except for
#every four centuries, so I need to remove the centuries
century_list = ["0"]
for item in range(0, 3000, 4):
....comparison = str(item)[-2:]
....if comparison == "00":
........century_list.append(item)
....else:
........print item
#now go through our list of centuries and also show only every fourth item
list_length = len(century_list)
#print century list to see how we're doing
print century_list
for item in range(0, list_length, 4):
....print century_list[item]

2 comments:
I liked your article, and it really taught me a lot about myspace, but what's up with the background?
Thanks. Uh, what background? Here? That's just my blog background. On MySpace? That's some of my comics work. I work in comics, doing color art for Marvel Comics.
Post a Comment