[Tutor] (no subject)

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Nov 7 13:06:23 CET 2012


It's good to give your email a subject line that describes what you're doing.

On 7 November 2012 11:53, steve clarke <sclarkey101 at hotmail.com> wrote:
> Hi, I am trying to write a programme to count how many times a random point
> lies within the positive sector of a circle. So far I can display if the
> point lies inside the area but I need something to allow me to count the
> total number of items that lie inside the area.

The indentation below is all screwed up. I think this is because you
posted in html email. It is better to use plain-text email when
sending to this list so that the code doesn't get garbled.

> My programme is:
>>>> import random
>>>> for i in range(10):

All of the lines below are executed repeatedly in a loop

> x = random.random()
> y = random.random()
> count = 0

including the line above that sets count to 0.

> if x*x + y*y < 1:
> count = count + 1

So when you increment count above it has always been set to zero
first. You need to set count to zero once before the loop. Then
increment it by one on each iteration of the loop (if the point is in
the circle).


Oscar


More information about the Tutor mailing list