Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
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
kaelynw: art igg
2 hours ago 6 Replies 1 Medal
XShawtyX: Art
14 hours ago 6 Replies 0 Medals
Nina001: teach me how to draw or just tell me the basics
16 hours ago 2 Replies 1 Medal
XShawtyX: We doing another drawing gimme ideas to add to this
17 hours ago 9 Replies 1 Medal
RAVEN69: What is x 3+y 3+z 3=k
21 hours ago 20 Replies 1 Medal
cinna: Who is good with photo editing? Dm me pls
1 day ago 2 Replies 0 Medals
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!