Thursday 19 September 2024

Practical - 70 - Write a program in python to generate the sequence: -1, 2, -3, 4, -5, …n, where n is an integer and its value should be taken as n input from the user.

Practical - 70 - Write a program in python to generate the sequence: -1, 2, -3, 4, -5, …n, where n is an integer and its value should be taken as n input from the user.

Ans:

n=int(input("Enter Number of terms in sequence = "))

for i in range(1,n+1):

    a=i*(-1)**i

    print(a,end=",")

 

Output:

Enter Number of terms in sequence = 8

-1,2,-3,4,-5,6,-7,8,


No comments:

Post a Comment