Python Forum
Write a program to compute the sum of the terms of the series: 4 - 8 + 12 - 16 + 20 -
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write a program to compute the sum of the terms of the series: 4 - 8 + 12 - 16 + 20 -
#1
#Write a program to compute the sum of the terms of the series: 4 - 8 + 12 - 16 + 20 -
24 + 28 - 32 + .... +/- n, where n is an input. Consider that n is always valid (which
means it follows the series pattern).

n = int(input("Enter n: "))
sum = 0
for i in range(4,n+4,4):
    sum += i - (i+2)
print("The sum of %s first terms is: %s"%(n,sum))
I want to know what I'm doing wrong
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Write a program in python lana 6 1,217 Oct-11-2023, 05:30 PM
Last Post: deanhystad
Photo How can I write a Python program for this structogram? rauljp9483 6 57,904 Nov-24-2021, 06:57 AM
Last Post: buran
  Maths and python: Compute stress level cheerful 1 2,706 Oct-20-2021, 10:05 AM
Last Post: Larz60+
  Compute complex solutions in quadratic equations liam 1 1,879 Feb-09-2020, 04:18 PM
Last Post: Gribouillis
  How to compute conditional unigram probabilities? jbond 2 2,506 Jan-25-2020, 02:58 PM
Last Post: jbond
  [split] Please advise how to write this program Rmasson 4 3,137 Apr-20-2019, 01:53 AM
Last Post: Skaperen
  To extract a specific column from csv file and compute the average vicson 2 8,091 Oct-20-2018, 03:18 AM
Last Post: vicson
  How do you compute tf-idf from a list without using the counter class syntaxkiller 8 5,194 Dec-01-2017, 05:24 PM
Last Post: nilamo
  compute gross pay jamesuzo 1 10,309 Sep-07-2017, 01:47 PM
Last Post: ichabod801
  given 2 base 20 numbers write a program to subtract second from the first and return dp_tisha 2 3,740 Jul-06-2017, 09:22 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020