Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

Write a program that defines a recursive function sum_ints(x) that returns the sum of all the ints in x. Here is how to "sum all the ints in x": * If x is an int, return x. * If x is a list, return the sum of all the ints in x, or in lists contained in x. * Otherwise, return 0. Here are some examples: * sum_ints(3) = 3 * sum_ints('a') = 0 * sum_ints('3') = 0 * sum_ints(3.0) = 0 * sum_ints([3]) = 3 * sum_ints([]) = 0 * sum_ints([[[[3]]]]) = 3 * sum_ints([[2], 3, [[4, 5, 'a']]]) = 14 * sum_ints({1: 2, 3: 4}) = 0 * sum_ints((1, 2, 3, 4)) =

OpenStudy (anonymous):

This is not do your assignment forum,you can try yourself and if your struck we can help you

OpenStudy (anonymous):

hmmm, here is a hint int main() { \\find sum of 3 int val = sum_all_ints(3); } int sum_all_ints(int i) { \\Check values and strip rubbish \\check boundary condition. very important and return 0, what about negatives? return (i + sum_all_ints( i-1 )); } Haven't test or even compiled it but you should get the idea

OpenStudy (anonymous):

well Im more of python person

OpenStudy (anonymous):

A Pythonic guy will not ask this question for others to answer.

OpenStudy (anonymous):

Well, take it for what it is and run with it :D

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!
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!