Python problem

A

ach360

I'm so lost. Given the formula pi=4-4/3+4/5-4/7+4/9-4/11+...... How do I print a table showing approximate value of pi by computing one term4-4/3 then two terms4-4/3+4/5, and so on.Then how many terms of the series before Iget 3.14, 3.141, 3.1415, 3.14159. Please helps computer teacher literally says figure it out and doesn't help and expects a perfect program.this is in python 3 please give an answer I can understand and an example.
Thanks :) :)
I need this right now.
Thanks for your time.

I need this ASAP
 
D

Dennis Lee Bieber

I'm so lost. Given the formula pi=4-4/3+4/5-4/7+4/9-4/11+...... How do I print a table showing approximate value of pi by computing one term4-4/3 then two terms4-4/3+4/5, and so on.Then how many terms of the series before I get 3.14, 3.141, 3.1415, 3.14159. Please helps computer teacher literally says figure it out and doesn't help and expects a perfect program.this is in python 3 please give an answer I can understand and an example.
Thanks :) :)
I need this right now.
Thanks for your time.

I need this ASAP

It is homework... No one will give you an answer... Normally we'd
ask you to show use what you have tried, and we'd try to suggest where
you went wrong. I'll give you five hints...

HINT: The first term of the equation is equivalent to 4/1
HINT: The denominators are odd integers.
HINT: Each iteration is adding 4/<nextodd> to the preceding sum
HINT: Subtraction is the addition of a negative value
HINT: Each "even" term is a subtraction
 
S

Steven D'Aprano

I'm so lost. Given the formula pi=4-4/3+4/5-4/7+4/9-4/11+...... How do I
print a table showing approximate value of pi by computing one term4-4/3
then two terms4-4/3+4/5, and so on.Then how many terms of the series
before I get 3.14, 3.141, 3.1415, 3.14159. Please helps computer teacher
literally says figure it out and doesn't help and expects a perfect
program.this is in python 3 please give an answer I can understand and
an example. Thanks :) :)

First, you need to know what the formula for pi actually is. You can find
that by googling, or look it up in a maths book. You should expect
something like

pi = sum from i=0 to infinity of 4 divided by (something)


Then you want a program to print a table that looks something like this:

i value
0 xxxxx
1 xxxxx
2 xxxxx


etc., where the "xxxxx" will get filled in later, and the table stops at
a certain maximum value of i. Here is a hint:


for i in range(100):
x = "calculate something"
print("%d %s" % (i, x)


Does that get you started? Try writing some code and see how far you get.


Good luck!



I need this right now.
Thanks for your time.

I need this ASAP

Then you better get started straight away then. Turn off Facebook and
Twitter and do some real work.
 
A

ach360

Loop_variable= 1
Pi=1.0
term=0
T=1.0
While (loop_variable> 0):
Loop_variable=Loop_variable+1
T=T+2.0

If (loop_variable%2 ==0):
Term=0;
Else:
term=1;


If term ==0:
Pi=Pi- float(1/T);
Else:
Pi=Pi+ float(1/T);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top