Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (itz_sid):

Can someone look over my short code? I am getting a logical error and am confused as to why it is not giving me the correct data.

OpenStudy (itz_sid):

OpenStudy (sapphiremoon):

Haven't done too much work with Python arrays, but that seems to be where your problem is... Doesn't look like there's anything wrong with the code though, have you tried printing at various stages in the program what it thinks the values are?

OpenStudy (itz_sid):

When I take out the Month Variables, it outputs the correct values. But when I try to put the names of the month, it keeps saying April and September every time.

OpenStudy (sapphiremoon):

What's that list where it sets January = Jan etc. for? And could you try switching the order of Months and Months_Rainfall for me? (Also what does that do, I mentioned I wasn't good with arrays...)

OpenStudy (itz_sid):

What i mean is that If I take out the Month Name Variables, then it outputs the data correctly as such

OpenStudy (itz_sid):

And Here it is in the switched Order, It just switches the April and September in the output.

OpenStudy (sapphiremoon):

Hmm... I noticed that when it outputs the highest rainfall, it outputs the month with index 3, and the highest rainfall was 3.0... I don't know if that's significant... And I meant in the variable declaration for the array change it to Months_Rainfall, Months (I don't know if that'll do anything but... not actually on my computer with IDLE)

OpenStudy (itz_sid):

Sorry, I didnt quite get what you were saying

OpenStudy (sapphiremoon):

Hang on, lets see if I can get an online IDE going and try my changes myself, lol.

OpenStudy (itz_sid):

OKay. lol

OpenStudy (sapphiremoon):

I found the problem! The compiler was finding the max of the months in the first array, and it was choosing September as the max and April as the min because they're the highest and lowest *alphabetically*. I wrote some code to fix it, you might be able to simplify it.

OpenStudy (sapphiremoon):

On the first line, the month names keep going across as normal. (window's not wide enough, lol).

OpenStudy (itz_sid):

Oh so why did you have to put months[month_rainfall.index(min(month_rainfall))] Seems like extra work. Like i dont know how the "Index" part works.

OpenStudy (itz_sid):

Hm, but now i get this error

OpenStudy (sapphiremoon):

It's the mas of Months_Rainfall, not the max of Months. The index part finds the index of the maximum value of months_rainfall and the selects that index from the months array to get the correct name. @iTz_Sid

NvidiaIntely (nvidiaintely):

^^^ Good job @SapphireMoon! ^^^

OpenStudy (itz_sid):

It worked! But is there an easier way to do this? Because I haven't learned this method. xD

OpenStudy (sapphiremoon):

I don't know, that's just what my debugging produced, had to Google to see if there was a method that would find the index like in Java, but it's not that difficult to understand, I don't think...

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!