So how would I go about creating a simple program like this using a for-loop? It would ask the user for an input and then print the following pattern for the appropriate number of terms, and it can't use if-else statements
Example:
How many terms would you like?
Input: 9
Output: 1 1 3 3 5 5 7 7 9
CodePudding user response:
I hope you can work out how to input a number yourself. The following use of a for-loop creates the sequence you want:
users_input = 9
print("Output: ",end="")
for i in range(users_input):
print(1 2*(i//2),end=" ")
print()
Output: 1 1 3 3 5 5 7 7 9
