Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #RecursiveMaxFinder.py
- #recursive function finds highest integer in list
- def findMax(li):
- #if only 1 item in list, return it
- if len (li)==1: return li[0]
- #return the greater of (firstlistitem, maximumoftheotherlistitems)
- return max (li[0], findMax (li[1:]))
- def main():
- a_list = [ 8, 3, 4, 5, 7, 1, 2, 6, 9 ] # test values: try different values, e.g. remove 9
- print ("List: %s" % a_list) # print list
- print ("Highest number: %d" % findMax (a_list)) # print output of function findMax()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement