Ask your own question, for FREE!
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW) 19 Online
OpenStudy (vahidp):

does anyone here figure out what's wrong with my code? n = [3,5,7] def myFun(n): for i in n: count += n[i] return count I get this error: Oops, try again. Did you create a function called myFun?

OpenStudy (anonymous):

Are u trying to add the numbers in the list? Can u not just use sum(n)? http://www.codeskulptor.org/#user2-RDJPJlggH4-0.py

OpenStudy (turingtest):

not exactly sure why it gives an infinite loop, but for one thing you want to increment count+=i not count+=n[i] as the second i=3, so n[3] would be out of range of the index

OpenStudy (turingtest):

first i*

OpenStudy (turingtest):

You also didn't initiate a value for count. Try this. def myFun(n): count=0 for i in n: count += i return count

OpenStudy (anonymous):

If u want to use the loop, then I did it here: http://www.codeskulptor.org/#user2-iGaXMs9jPu-0.py Problem is you didn't assign a start value for count.

OpenStudy (vahidp):

thank you, estudier and Turning Test! the problem was n[i] :)

OpenStudy (anonymous):

ur welcome

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!