don't get why my code doesn't work...?
The assignment: Write a recursive function index_of_max(nums) that returns the index of the maximum value in the input list of numbers, leaving the original list unchanged.
Here's my code:
def index_of_max(nums):
if nums == []:
return "empty list" #base case 1
if len(nums) == 1:
return 0 #base case 2
else:
x = nums[0]
lst = nums[1:]
if x > index_of_max(lst):
return nums.index(x)
else:
return index_of_max(lst)