agenda generator , help ..

Hi , here is my code ,

 
week = ["Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"]
yearm = ["January","February","March","April","May","June","July","August","September","October","November","December"]
yeard = [31,29,31,30,31,30,31,31,30,31,30,31]
agenda = open("agenda.txt","w")
month , y , z = 0,0,0
for d in range(1,366):
    agenda.write("
Day Number"+str(d)+",")
    agenda.write(str(yearm[month]))
    if month > int(yeard[month]) :
            month += 1
agenda.close()
 

i want the agenda to do like follows in the outpot text


Day Number 1 , January 1 , Saturday
[-----]
~Done
~To Do
Day Number 2 , January 2 , Monday
[-----]
~Done
~To Do

till the last day of year , i think it is too cunning , i wrote a lot and tried and snipped the script to it’s baisc form above due to disperation :frowning:

help .

Hmm… wasn’t this supposed to be in the ‘Python’ thread? But we’ll try an’ help .

Anyway, what’s wrong with the output, I mean what is the output? Isn’t it what it’s supposed to be?

the txt outpot says

Day Number1,January
Day Number2,January
Day Number3,January
Day Number4,January
Day Number5,January
Day Number6,January
Day Number7,January
Day Number8,January
Day Number9,January
Day Number10,January
Day Number11,January
Day Number12,January
Day Number13,January
Day Number14,January
Day Number15,January
Day Number16,January
Day Number17,January
Day Number18,January
Day Number19,January
Day Number20,January
Day Number21,January
Day Number22,January
Day Number23,January
Day Number24,January
Day Number25,January
Day Number26,January
Day Number27,January
Day Number28,January
Day Number29,January
Day Number30,January
Day Number31,January
Day Number32,January
Day Number33,January
Day Number34,January
Day Number35,January
Day Number36,January
Day Number37,January
Day Number38,January
Day Number39,January
Day Number40,January
Day Number41,January
Day Number42,January
Day Number43,January
Day Number44,January
Day Number45,January
Day Number46,January
Day Number47,January
Day Number48,January
Day Number49,January
Day Number50,January
Day Number51,January
Day Number52,January
Day Number53,January
Day Number54,January
Day Number55,January
Day Number56,January
Day Number57,January
Day Number58,January
Day Number59,January
Day Number60,January
Day Number61,January
Day Number62,January
Day Number63,January
Day Number64,January
Day Number65,January
Day Number66,January
Day Number67,January
Day Number68,January
Day Number69,January
Day Number70,January
Day Number71,January
Day Number72,January
Day Number73,January
Day Number74,January
Day Number75,January
Day Number76,January
Day Number77,January
Day Number78,January
Day Number79,January
Day Number80,January
Day Number81,January
Day Number82,January
Day Number83,January
Day Number84,January
Day Number85,January
Day Number86,January
Day Number87,January
Day Number88,January
Day Number89,January
Day Number90,January
Day Number91,January
Day Number92,January
Day Number93,January
Day Number94,January
Day Number95,January
Day Number96,January
Day Number97,January
Day Number98,January
Day Number99,January
Day Number100,January
Day Number101,January
Day Number102,January
Day Number103,January
Day Number104,January
Day Number105,January
Day Number106,January
Day Number107,January
Day Number108,January
Day Number109,January
Day Number110,January
Day Number111,January
Day Number112,January
Day Number113,January
Day Number114,January
Day Number115,January
Day Number116,January
Day Number117,January
Day Number118,January
Day Number119,January
Day Number120,January
Day Number121,January
Day Number122,January
Day Number123,January
Day Number124,January
Day Number125,January
Day Number126,January
Day Number127,January
Day Number128,January
Day Number129,January
Day Number130,January
Day Number131,January
Day Number132,January
Day Number133,January
Day Number134,January
Day Number135,January
Day Number136,January
Day Number137,January
Day Number138,January
Day Number139,January
Day Number140,January
Day Number141,January
Day Number142,January
Day Number143,January
Day Number144,January
Day Number145,January
Day Number146,January
Day Number147,January
Day Number148,January
Day Number149,January
Day Number150,January
Day Number151,January
Day Number152,January
Day Number153,January
Day Number154,January
Day Number155,January
Day Number156,January
Day Number157,January
Day Number158,January
Day Number159,January
Day Number160,January
Day Number161,January
Day Number162,January
Day Number163,January
Day Number164,January
Day Number165,January
Day Number166,January
Day Number167,January
Day Number168,January
Day Number169,January
Day Number170,January
Day Number171,January
Day Number172,January
Day Number173,January
Day Number174,January
Day Number175,January
Day Number176,January
Day Number177,January
Day Number178,January
Day Number179,January
Day Number180,January
Day Number181,January
Day Number182,January
Day Number183,January
Day Number184,January
Day Number185,January
Day Number186,January
Day Number187,January
Day Number188,January
Day Number189,January
Day Number190,January
Day Number191,January
Day Number192,January
Day Number193,January
Day Number194,January
Day Number195,January
Day Number196,January
Day Number197,January
Day Number198,January
Day Number199,January
Day Number200,January
Day Number201,January
Day Number202,January
Day Number203,January
Day Number204,January
Day Number205,January
Day Number206,January
Day Number207,January
Day Number208,January
Day Number209,January
Day Number210,January
Day Number211,January
Day Number212,January
Day Number213,January
Day Number214,January
Day Number215,January
Day Number216,January
Day Number217,January
Day Number218,January
Day Number219,January
Day Number220,January
Day Number221,January
Day Number222,January
Day Number223,January
Day Number224,January
Day Number225,January
Day Number226,January
Day Number227,January
Day Number228,January
Day Number229,January
Day Number230,January
Day Number231,January
Day Number232,January
Day Number233,January
Day Number234,January
Day Number235,January
Day Number236,January
Day Number237,January
Day Number238,January
Day Number239,January
Day Number240,January
Day Number241,January
Day Number242,January
Day Number243,January
Day Number244,January
Day Number245,January
Day Number246,January
Day Number247,January
Day Number248,January
Day Number249,January
Day Number250,January
Day Number251,January
Day Number252,January
Day Number253,January
Day Number254,January
Day Number255,January
Day Number256,January
Day Number257,January
Day Number258,January
Day Number259,January
Day Number260,January
Day Number261,January
Day Number262,January
Day Number263,January
Day Number264,January
Day Number265,January
Day Number266,January
Day Number267,January
Day Number268,January
Day Number269,January
Day Number270,January
Day Number271,January
Day Number272,January
Day Number273,January
Day Number274,January
Day Number275,January
Day Number276,January
Day Number277,January
Day Number278,January
Day Number279,January
Day Number280,January
Day Number281,January
Day Number282,January
Day Number283,January
Day Number284,January
Day Number285,January
Day Number286,January
Day Number287,January
Day Number288,January
Day Number289,January
Day Number290,January
Day Number291,January
Day Number292,January
Day Number293,January
Day Number294,January
Day Number295,January
Day Number296,January
Day Number297,January
Day Number298,January
Day Number299,January
Day Number300,January
Day Number301,January
Day Number302,January
Day Number303,January
Day Number304,January
Day Number305,January
Day Number306,January
Day Number307,January
Day Number308,January
Day Number309,January
Day Number310,January
Day Number311,January
Day Number312,January
Day Number313,January
Day Number314,January
Day Number315,January
Day Number316,January
Day Number317,January
Day Number318,January
Day Number319,January
Day Number320,January
Day Number321,January
Day Number322,January
Day Number323,January
Day Number324,January
Day Number325,January
Day Number326,January
Day Number327,January
Day Number328,January
Day Number329,January
Day Number330,January
Day Number331,January
Day Number332,January
Day Number333,January
Day Number334,January
Day Number335,January
Day Number336,January
Day Number337,January
Day Number338,January
Day Number339,January
Day Number340,January
Day Number341,January
Day Number342,January
Day Number343,January
Day Number344,January
Day Number345,January
Day Number346,January
Day Number347,January
Day Number348,January
Day Number349,January
Day Number350,January
Day Number351,January
Day Number352,January
Day Number353,January
Day Number354,January
Day Number355,January
Day Number356,January
Day Number357,January
Day Number358,January
Day Number359,January
Day Number360,January
Day Number361,January
Day Number362,January
Day Number363,January
Day Number364,January
Day Number365,January

Yeah, well I suppose it’s just a matter of nested-for loops, i.e., a for loop inside another.
Something like:


    for m in yearm
        for d in m
        output=> "Day number " + d + m 
        d+=1
    m+=1

You’ll have to make changes though.

I’m not familiar with the python syntax, and the for-in keyword, because the ‘C’ ‘for’ is quite different. But the logic should remain the same…

Looks to me that one problem might be that it isn’t associating the months with the length of the months.

Try using a dictionary with keywords being the months, and the values being the number of days.

Or, if you want to use a list so you can sort the months, use a list of dictionaries, with each dictionary being its own month, like this:

year = [{“month”: “January”, “days”: 31, “order”: 1}, {“month”: “February”, “days”: 29, “order”: 2}, {“month”: “March”, “days”: 31, “order”: 3}]

This way you can list them in order using the value of “order”, keep track of the number of days with the value of “days”, and the name of the month with the value of “month”.

Alternatively, you could try to create a new class for month, and have it hold the data for number of days etc.

Hmm, I wrote it in C, and tried to convert it into python. Here it is:


day=[Saturday, Sunday....]
month=[January, February ...]
monthd=[31,29...]
agenda=open("agenda.txt","w")
for a in range (1, 12)
    for b in range (1, monthd[a])
        for c in range (1, 7)
        agenda.write ("
 Day number"+ b + "," + month[a] + " " + day[c] )
agenda.close()

And that should do it…

What I don’t understand is how you want the ~to-do and ~done thing to come… I suppose that could just be added as a agenda.write statement…

and, you don’t actually have to make your own month and day name lists, for example calendar module in python already has those…


import calendar
print calendar.month_name[1]
print calendar.day_name[1]

calendar module is very good for all sort of date related things… check it out.

.b

the blenderer , i have a question , are nested loops a common thing in coding , i mean , when they done blender , is it common for the Devs to have something like 8 loops in each other like that , i consider it confusing a little … :frowning: .

good idea that you gave me there , thanks ,

@ basse , thanks man …

Well, I can’t say much about blender, though they probably do have a few of them, but it’s quite common in programming, yeah. Usually though, there are only two loops, unlike this example, which has 3 loops.

And I must admit, nested loops HORRIFIED me at first. Pretty confusing, they are…

@basse: Although I agree with you, i.e., to use the calender module, but doesn’t it only print the current day/date/month?

I don’t know, but that’s what I think…

i am not sure what you are saying, but it doesn’t only print out current date.
http://docs.python.org/library/calendar.html#module-calendar

.b

Okay, Like I said, I didn’t know about that. That makes my code useless :stuck_out_tongue: :smiley:

i didn’t mean to have the agenda , i was just training my coding skills , thanks both , any more idea are welcome .

The reason the first one failed is that it was saying this line:


    if month > int(yeard[month]) :
            month += 1

Here, “month” is between 0 and 11, and you are asking if it is greater than 29, 30 or 31.

week = ["Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"]
yearm = ["January","February","March","April","May","June","July","August","September","October","November","December"]
yeard = [31,29,31,30,31,30,31,31,30,31,30,31]
agenda = open("agenda.txt","w")
month , y , z = 0,0,0
dayOfMonth=0
for d in range(1,366):
    dayOfMonth+=1
    agenda.write("
Day Number"+str(d)+",")
    agenda.write(str(yearm[month]))
    if dayOfMonth > int(yeard[month]) :
            month += 1
            dayOfMonth=0
agenda.close()

That is at least a guide to the solution. What’s really important is the way in which you can find out why your program has gone wrong.

My train of thought:
Always prints out January.
Why does it print out the month?
" agenda.write(str(yearm[month]))"
Month must == 0 for this to be true.
Where does it get set to 0?
At the beginning.
Where should it be changed?
Why is it not being changed in this case?

Learning to debug programs is, I would argue, more important than learning new features.

And I must admit, nested loops HORRIFIED me at first. Pretty confusing, they are…

Coding style is the way through this. Unless you’re iterating over an 9 dimensional array, you probably shouldn’t have a 9 level explicit nesting, separating it into functions can increase readability massively.

The other thing is the way of thinking about it. Ignoring levels above can usually be done. Thinking in the way of “I need to do abstracted idea to all of the parts of this array, now, what do I need to do to get abstracted idea working”.

sorry for reviving this , but it’s important for me …