Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 10 Online
OpenStudy (anonymous):

hello, first time here, I am trying for several times with greedy advisor but still not suceed, I created a code and it seems to work http://dpaste.com/hold/805992/ but when checking with ps9_test.py , it does not pass the test, could you help me, thanks.

OpenStudy (anonymous):

i am getting an index out of range error with your function, are you? if so, the condition in the while statement is suspect

OpenStudy (anonymous):

you probably is getting an 'index out of range' because the keys are within compare function first one is key and 2nd one is key +1 so that would run through first key and go until the last key plus one, that's something I have not been able to fix, would thank your help.

OpenStudy (anonymous):

(key+1)<len(subjectsCopyVal) This should stop index out of range.

OpenStudy (anonymous):

ok, it's done, but still when I run ps9_test.py, still not pass this test, it says something about what comes and what it does expect.

OpenStudy (anonymous):

your algorithm checks/compares each item in the list to the next item in the list what your algorithm should do is find the best item in the list, then find the next best ... one way to do this is to: - have a variable that 'holds' the best item that has been found maybe call it best - initialize best to a 'bad' value (something that will always lose a comparison) - compare every item in the list against best - if an item is better than best, assign that item to best - after you have run through the whole list, best should contain the best item in the list - go through the list again, to get the next best till no more work is available - the second and subsequent times through the list you have to make sure you don't choose any items that hae already been taken

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!