31 Mar PMCA Saturday 18:30 Python Homework 22.03.26.
Question 1:
Use recursion to write a function has_digit
that consumes a string and produces True
if the string contains a digit (0 through 9) and False
otherwise.
Hints:
-
- Make sure that you have a base case.
- Make sure to use the function on a shorter string.
- Before calling the function, first check to see if the string is empty or if the first character is a digit.
Question 2:
Use recursion to write a function is_sorted
that consumes a list of numbers and produces True
if the items in the list appear in sorted order and False
otherwise. A list of length zero or one is always in sorted order.
Hints:
-
- Make sure that you have a base case.
- Make sure to use the function on a shorter list.
- Before calling the function, first check to see if the list is of length zero or one or if the first number is larger than the second number.
Sorry, the comment form is closed at this time.