编写一个Python程序来查找系列的总和: - X - X ** 2/2! + X ** 3/3! - X ** 4/4! + X ** 5/5! - X ** 6/6! [英] 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!
问题描述
编写一个Python程序来查找系列的总和: - X - X ** 2/2! + X ** 3/3! - X ** 4/4! + X ** 5/5! - X ** 6/6!
我尝试过:
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
推荐答案
您在第1行声明X
(大写),但你稍后会参考x
(小写),这是不存在的。
行
You declareX
(upper case) in line 1, but you later refer tox
(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.
for i in range(1,x+1):
for i in range(1,j+1):
使用我
因为循环的2个嵌套的计数器也是一个错误。
Using i
as the counter of 2 nested for
loops is an error too.
Sum += (Sign*(X**i)/Fact*j
这里你给了2 (
bit只有1 )
建议:拿一张纸写下你所有的东西每个元素的总和为1行,每个元素为1列。
然后你的程序需要准备每个部分,然后更新总和。
Don不介意在代码中使用注释。
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.
这篇关于编写一个Python程序来查找系列的总和: - X - X ** 2/2! + X ** 3/3! - X ** 4/4! + X ** 5/5! - X ** 6/6!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!