Print the number series 1 -2 3 -4 5 using while loop in Python
while Loop - Question 5
In this question, we will see how to print the number series 1 -2 3 -4 5 -6... up to nth term in Python programming using while loop. To know more about while loop click on the while loop lesson.
Q5) Write a program in Python to print the number series given below using while loop.
1 -2 3 -4 5 -6... up to nth term
Program
i=1; s=1
n=int(input('Enter nth term '))
while i<=n:
print('%d ' %(i*s),end='')
s=s*-1 # changing the sign
i=i+1
Output
Enter nth term 10 1 -2 3 -4 5 -6 7 -8 9 -10