Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Programing Implement the function makeNeg() that takes a list of numbers

ID: 671650 • Letter: P

Question

Python Programing

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:

Explanation / Answer

def input_and_res():

    try:

        a = raw_input("Enter no. :- ")

        n = int(a)

    except Exception:

        print "-----------------------------------"

        print "Please Enter No. ", "( The Number you entered is not a number )"

        input_and_res()

    else:

        if n > 0:

            print "Number is Positive"

        elif n < 0:

            print "Number is Negative"

        else:

            print "Number is ZERO"

        want_restart()

def check_y_n(check_result):

    if check_result == 'Y':

        input_and_res()

    elif check_result == 'N':

        print (" !!! Program Quit !!!")

    else:

        print ("Invalid Option Make sure that you type (Y / N)")

        print ("Continue..")

        want_restart()

def want_restart():

    print " Want to Restart Program, if Yes then Enter 'Y' and if No enter 'N' :- ",

    try:

        check_result = raw_input()

    except Exception as e:

        print "Sorry Error Occured: ", e

    else:

        check_y_n(check_result)

def main():

    """Main function"""

    input_and_res()

if __name__ == "__main__":

    main()