def f(x): #These next two lines of code define f(x) as the function (.5)^x return 1/(x**1.1) n=int(input("What is the value of n?")) #This asks for an n value. This is how many values you go out when approximating the sum. partsum=0 #These next two lines just implement two more functions and define the starting value i=1 while (i<=n): #This is a while statement saying that "while i is less than or equal to" this allows a process only when this is true print(i,f(i),partsum) #Prints f(x) with i plugged in for x partsum=partsum + f(i) #The next part sum is the previous partsum plus f(i) i=i+1 #Defines the next I value print("The partial sum is ", partsum) #Prints your anwser
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question