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?
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
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
first i*
You also didn't initiate a value for count. Try this. def myFun(n): count=0 for i in n: count += i return count
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.
thank you, estudier and Turning Test! the problem was n[i] :)
ur welcome
Join our real-time social learning platform and learn together with your friends!