Note: I am not an official teacher or GSI for any of the courses listed on this site unless otherwise stated. Any problems and notes are created from my own observations and may not accurately reflect the course's content.

Recursion #1

The is_increasing function takes a non-negative integer, n, and returns True if all the digits in n, from left to right, are larger than the previous digit, otherwise returns False. Refer to the doctests for examples how to use the is_increasing function.

def is_increasing(n, prev=10):
	""" Determine if a number is composed of only increasing digits.
	
		   >>> is_increasing(12379)
           True
           >>> is_increasing(124324)
           False
           >>> is_increasing(4)
           True
           >>> is_increasing(1790)
           False
           >>> is_increasing(0)
           True
           >>> is_increasing(245678)
           True
           """
	if _________________________________ :
		return True
	n, last = ______________________ , ______________________
	return ___________________________ and is_increasing( ___________________________ )

Solution

Have a question? Found an error? Email me at imran.khaliq@berkeley.edu with the URL of the page and a short description.