I need to write a function that generates a list of n odd numbers, starting at 1. For example, if the input is 12, the output would be
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]. I just started to learn python like 3 days ago and I have no idea where to start.
I was able to solve the similar question:
"Write a function that generates the first n natural numbers, starting at 1. The natural numbers are 1, 2, 3, 4, 5, ... You will need to create an empty list, add the numbers one by one, and return the list." with below code
I think the solution for this problem would be similar to this code, but I have no idea where to fix.
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]. I just started to learn python like 3 days ago and I have no idea where to start.
I was able to solve the similar question:
"Write a function that generates the first n natural numbers, starting at 1. The natural numbers are 1, 2, 3, 4, 5, ... You will need to create an empty list, add the numbers one by one, and return the list." with below code
def natural(n): L = list(range(n+1)) L = [num for num in L if num] return L
I think the solution for this problem would be similar to this code, but I have no idea where to fix.