



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




MIT OpenCourseWare http://ocw.mit.edu
Fall 2008
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.
def f(x): xs = str(x) if len(xs) == 1: return int(xs) n = int(xs[0]) + int(xs[1]) if len(xs) == 2: return n else: return n + f(xs[2:])
Python function that accepts an integer, num , as an argument and decides whether or not it is possible to buy num nuggets at McDonalds.
def f(n): s = str(n) if len(s) <= 1: return s return s[-1] + f(int(s[:-1]))