Answer:
def remove_evens(nums):
# Create an empty list to hold the odd numbers
odds = []
# Loop through the input list and check if each number is odd
for num in nums:
if num % 2 != 0:
odds.append(num)
# Return the list of odd numbers
return odds
if __name__ == '__main__':
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
result = remove_evens(nums)
print(result)
Step-by-step explanation:
In this implementation, we first create an empty list called odds to hold the odd numbers. We then loop through the input list nums, checking if each number is odd using the modulus operator (%). If the number is odd, we append it to the odds list.
Finally, we return the odds list, which contains only the odd numbers from the input list. In the main program, we pass the input list [1, 2, 3, 4, 5, 6, 7, 8, 9] to the remove_evens() function, and print the resulting list [1, 3, 5, 7, 9].