Click here to Skip to main content
14,459,108 members
Rate this:
Please Sign up or sign in to vote.
See more:
Write A Python Program To Find The Sum Of The Series:- X - X**2/2! + X**3/3! - X**4/4! + X**5/5! - X**6/6!

What I have tried:

X = int(raw_input("Enter the value for x:"))
j = int(raw_input("Enter The value for j:"))
Sum = 0
Fact = 1
Sign = 1
for i in range(1,x+1):
     for i in range(1,j+1):
               Fact = Fact*1
Sum += (Sign*(X**i)/Fact*j
Posted
Updated 5-Jan-20 20:21pm
v2
Comments
Member 12723370 6-Sep-16 12:21pm
   
in my source code there is some syntax error please check it and peruse my source code and suggest changes to it or a new source code will be gladly welcomed
Richard MacCutchan 6-Sep-16 13:05pm
   
In future please show us the complete text of any errors, and which lines they refer to.
Patrice T 6-Sep-16 13:28pm
   
Use Improve question to update your question.
Member 12723370 6-Sep-16 13:54pm
   
X = int(raw_input("Enter the value for x:"))
j = int(raw_input("Enter The value for j:"))
Sum = 0
Fact = 1
Sign = 1
for i in range(1,x+1):
for i in range(1,j+1):
Fact = Fact*1
Sum += (Sign*(X**i)/Fact*j
here a red line appears saying there is syntax error
Patrice T 6-Sep-16 14:12pm
   
Use Improve question to update your question.
Comments can't display indentations.
Rate this:
Please Sign up or sign in to vote.

Solution 1

You declare X (upper case) in line 1, but you later refer to x (lower case), which does not exist.
The line
Fact = Fact*1

does not do anything useful.
I also suspect the last line of your code should be indented the same as the previous line.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

for i in range(1,x+1):
     for i in range(1,j+1):

Using i as the counter of 2 nested for loops is an error too.
Sum += (Sign*(X**i)/Fact*j

Here you gave 2 ( bit only 1 )

Advice: take a sheet of paper and write all what you need with 1 line per element in the sum and 1 column for each piece of element.
Then your program will need to prepare each pieces and then update the sum.
Don't mind using comments in code.
   
v2
Comments
Member 12723370 6-Sep-16 22:32pm
   
Thank You For The Suggestion
Patrice T 6-Sep-16 22:57pm
   
Hope it helped.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100