Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

Python
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 15-Sep-20 18:51pm
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.

You declare X (upper case) in line 1, but you later refer to x (lower case), which does not exist.
The line
Python
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.
 
Share this answer
 
Python
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.
Python
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.
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900