Ask
your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW)
9 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
AndreW2002:
I'm trying to change my profile picture but it keeps saying "Either a error occurred, or you tried to upload a gif" but it's not a gif that I'm using, it's
Spongeboy:
if an earthquake measures a 7.5 on the Richter scale, how many buckets of water do you need to pour down a volcano to put it out before the tectonic plates
ShikuniShigana:
The first image is a drawing from 2 yrs ago, the second image is something I did
Spongeboy:
bossgirl I can see ur txt but I cant txt u back it doesn't let me
676767:
GUYSSSS ITS CHRISTMAS TIMEEE! IM SO HAPPY! I LOVE EVERY SINGLE ONE OF YOUUUU! I H
5 hours ago
1 Reply
0 Medals
1 day ago
0 Replies
0 Medals
2 days ago
1 Reply
0 Medals
3 days ago
4 Replies
1 Medal
2 days ago
4 Replies
0 Medals