I am having an issue getting the python 2.5 shell to do what I need to do. I am trying to have the user input a value for "n" representing a number of times the loop will be repeated. In reality, I need to have the user input N that will correspond to the number of terms from the Gregory–Leibniz series and outputs the approximation of pi.
Gregory–Leibniz series pi=4*((1/1)-(1/3)+(1/5)-(1/7)+(1/9)-(1/11)+(1/13)...)
So when n is 3,I need the loop calculates up to 1/5. Unfortunately, it is always giving me a value of 0 for the variable of total.
My code as of right now is wrong, and I know that. Just looking for some help. Code below:
def main(): n = int(raw_input("What value of N would you like to calculate?")) for i in range(1,n,7): total = (((1)/(i+i+1))-((1)/(i+i+2))+((1)/(i+i+4))) value = 4*(1-total) print(value) if __name__ == "__main__": main()
1/2==0. If you use1.0in place of1you will get float division instead.