Question: Implement the function makeNeg() that takes a list of numbers and a number representing an index as a parameter and changes the list item at
Implement the function makeNeg() that takes a list of numbers and a number representing an index as a parameter and changes the list item at the specified index to be negative. If the number at the specified index is already negative, the function shouldn't change the list. The function should verify that the index is correct for the list. If the index isn't valid for the list, the function shouldn't change the list. The information below shows how you would call the function makeNeg() and what it would display for several different parameters, including cases where an invalid index is provided:
Python 3.4.1 Shell File Edit Shell Debug Options Windows Help >>> Ist1 = [1, 2, 3, 4] >> makeNeg(lsti, 2 > lst1 >> makeNeg(lsti, 2 > lst1 >> makeNeg(lsti, 5) That index is invalid. The 1ist vas not changed lst1 >> makeNeg(lst1, -1) > lst1 >>> Ist2 = [-1, -2, -3, 0] >> makeNeg(lst2, 0) > lst2 [-1, 2,3 0] >> makeNeg(lst2, -4] > lst2 [-1, 2,3 0] >> makeNeg(lst2,5) That index is invalid. The 1ist vas not changed. lst2 [-1, 2,3 0] 272 Ln: 146 Col: 4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
