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

I don't get the program at the end of lecture 3. http://dpaste.com/603441/ why is the result 17?

OpenStudy (anonymous):

The function is summing the digits of the string, so 1+9+5+2 = 17

OpenStudy (anonymous):

sumDigits = 0 for c in str(1952): sumDigits += int(c) print sumDigits yeah, the for loop takes each digit, starting with the first and adds it to the previous, then prints the final result after the loop ends. sumDigits equals 1 on the first go around, then it equals 1 + 9 (10), then 10 + 5, etc.

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!
Latest Questions
AlphaUwU: - This is my art work -
4 hours ago 7 Replies 3 Medals
Ferrari: Calculate (7.013 x 10^u22128) + (2 x 10^u22128).
9 hours ago 2 Replies 1 Medal
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!