Jun-02-2020, 12:34 PM
Good job on remove_value()!
As for reverse():
1) I'm not sure what you're trying to accomplish in lines 32-33. It appears that if the variable is equal to -1, you are reassigning it the same value of -1. From the assignment and your comment in the program, it seems like the only check you need here is whether the entered number is less than 2.
2) There are problems with your approach in your for loop on lines 45-50. Keep in mind that when you use "for element in my_list:", you are iterating through the values in the list ('e', 'd', 'u', 'd' in the case of str_list6). That means the element variable is a string, and you therefore can't add or subtract the integer value 1. If your plan is to iterate through a list in reverse order, you can do that using range() and the length of the list. Just to illustrate, this code would print the values from my_list one at a time in reverse order:
As for reverse():
1) I'm not sure what you're trying to accomplish in lines 32-33. It appears that if the variable is equal to -1, you are reassigning it the same value of -1. From the assignment and your comment in the program, it seems like the only check you need here is whether the entered number is less than 2.
2) There are problems with your approach in your for loop on lines 45-50. Keep in mind that when you use "for element in my_list:", you are iterating through the values in the list ('e', 'd', 'u', 'd' in the case of str_list6). That means the element variable is a string, and you therefore can't add or subtract the integer value 1. If your plan is to iterate through a list in reverse order, you can do that using range() and the length of the list. Just to illustrate, this code would print the values from my_list one at a time in reverse order:
for i in range((list_length - 1), -1, -1): print(my_list[i])