one of my revision questions was to create a func that takes a list of integer values as a list, and convert every even number into an odd number.
Expected Output:
integer_list = [1, 2, 3 , 4, 5, 6, 7]
Before: [1, 2, 3, 4, 5, 6, 7]
After: [1, 3, 3, 5, 5, 7, 7]
integer_list = [1, -2, 3 , -4, 8, 16, 21, -17]
Before: [1, -2, 3, -4, 8, 16, 21, -17]
After: [1, -3, 3, -5, 9, 17, 21, -17]
Code thus far:
def make_all_odd(integer_list):
for number in integer_list:
if (number % 2) == 0:
number += 1
integer_list.append(number)
So far, I've only figured out that I need to iterate through every element in the list and check if it is even using a for loop, but I'm not sure how to modify the original string to change the identified even numbers into odd. I know my code just adds the recently converted even to odd numbers to the end of the list, but in my case I have to replace, not add. I first thought of using find() but that doesn't work for lists