Based on this ideea

You just wrote a loop allowing the input of 20 names into a list. Alas, you made an error as you entered name number 17. Redesign your input loop, so you can correct the error easily without having to retype the previous 16 names.

I wrote the following program

#!/usr/bin/python/ env

def input_numbers():

    #instantiate each variable
    elements = []
    # loop from 0 to 5 or iterate
    for i in range(0,5):

        numbers = raw_input("Enter a number:") 

    # add each number to the list

    # option chooser
    op = raw_input("Do you want to change an element in the list? y/n:")
    # as long as op is true do this block of code
    while op =="y":

        #option for exit(not a good one)
        op = raw_input("Are you going to change any elements after this one? y/n:")

        d = int(raw_input("Enter the position of the element:"))

        n = int(raw_input("Enter the new value:"))

        #change an element in the list using position and new value

    return elements

print "Your list is "+str(input_numbers())

I would like to know if there is a better way of creating this program,a much more performance driven way?

Thank you for any input

2 Years
Discussion Span
Last Post by pyTony
def lst_corrector(lst, index_vaule):
    value_change = raw_input('Enter correct value: ')
    for index, item in enumerate(lst):
        if index == index_to_change:
            lst[index] = value_change
            return lst

#Error should be car
lst = ['boat', 'train', 'carfd']
index_to_change = 2
print lst_corrector(lst, index_to_change)
#--> ['boat', 'train', 'car']
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.