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 = []
i=0
# 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
elements.append(numbers)
# 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
elements[d]=n
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