Ask
your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW)
15 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
October4:
For my lover~ I Love You, I Love You I am going to tell you a tale that is one hundred percent true.
Keyla:
Does any one have tips on helping me remember the differences in the three branches.
xXAikoXx:
How do I stop hating life? ... For the past 3 years I woke up everyday finding myself just completely drained and wanting everything to be over already.
MrMystery:
I have an assignment in my Senior Seminar class about 2 sentence horror stories,
Breathless:
Maybe once I may figure out. How time stops when your around Maybe one time I can figure how you send my heart into a beating rage Maybe I will understand h
Countless7Echos:
uuhh update: pushing to another project yayyy (simplified artstyle)
6 minutes ago
2 Replies
0 Medals
1 hour ago
0 Replies
0 Medals
6 hours ago
4 Replies
0 Medals
1 hour ago
1 Reply
0 Medals
1 hour ago
5 Replies
0 Medals
1 hour ago
6 Replies
0 Medals