Ask
your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW)
10 Online
I don't get the program at the end of lecture 3. http://dpaste.com/603441/ why is the result 17?
Still Need Help?
Join the QuestionCove community and study together with friends!
The function is summing the digits of the string, so 1+9+5+2 = 17
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!
Join our real-time social learning platform and learn together with your friends!
Latest Questions
thereneelg:
Alright so, I took my descriptive assessment about 2 or 3 weeks ago. My tutor on PAPER.
EdwinJsHispanic:
You forgot while I remembered And maybe its me that's short tempered It hurt like
Peer0Pressures0bad:
new favorite lyrics "Pisces and a Gemini But I think we might go really nice toge
EdwinJsHispanic:
what to do when you like TWO people your not supposed to ud83dude2dud83dude2d
EdwinJsHispanic:
I'm liking the wrong person more and more what do I do
2 hours ago
1 Reply
0 Medals
1 hour ago
5 Replies
1 Medal
5 hours ago
0 Replies
0 Medals
3 hours ago
10 Replies
1 Medal
1 day ago
21 Replies
3 Medals