Skip to content
Programming Exercises · Q5

Q.Write a program to generate the sequence: –5, 10, –15, 20, –25….. upto n, where n is an integer input by the user.

Telangana TsbieTextbookSubjective· 3mImportance★★★★★est
87% · 34/39 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Spot the pattern — the i-th term is 5 times i, with a minus sign at odd positions — then loop i from 1 to n printing 5*i negated when i is odd.

The idea: find the term's formula first. Writing the positions against the terms:

Position i12345
Term-510-1520-25

The magnitude is always 5 × i; the sign alternates, negative when i is odd, positive when i is even. Once the i-th term is expressible from i alone, a simple counted for loop generates the sequence. (We read "upto n" the standard way: n is the number of terms the user wants.)

Program

n = int(input("Enter the number of terms n: "))

for i in range(1, n + 1):
    term = 5 * i
    if i % 2 == 1:      # odd position -> negative term
        term = -term
    print(term, end=" ")
print()

Sample run

Enter the number of terms n: 6
-5 10 -15 20 -25 30

Trace for n = 6

i5 * ii odd?term printed
15yes-5
210no10

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.