# [Tutor] i have a question???

Michael Janssen mi.janssen at gmail.com
Thu Feb 3 16:49:13 CET 2005

```[the problem provided by alieks]
> >>"EXERCISE 3.9
> >>Use the math library to write a program to print out
> >>the sin and cos of numbers from 0 to 2pi in intervals
> >>of pi/6. You will need to use the range() function."

[Michael]
> > You _can_ do the exercise
> > with the range function but it would be easier without (eg. with a
> > while-loop).

[Pierre]
> I disagree ... :P And your next remark makes it clear range (or even
> better : xrange) is exactly what's needed for that problem !

[Michael's next remark]
> > Hint-no-solution: You will need a certain number of intervals, which
> > (the number of intervalls) is plain integer. Then translate from
> > current-intervall-number to pi'ish (sorry for that, my english ;-)
> > value.

You're right, I've described the range-solution. But what makes you
think, that the range-solution is actually the best/ simplest/
easiest? Within a while-loop you would increment your variable each
time by pi/6 and test if still lower-equal than 2*pi (need care for
float comparision) . With range you need to compute the "certain
number of intervals", then for-loop through the range-generated list
and compute the "pi'ish" value.

There's a loop one way or another ;-) Unless one want to add some
extra exercises like list comprehension and the map function. With the
while-loop, you don't need to know certainly which number of intervals
are needed, you just check if the upper boundary is reached.

Don't know, perhaps I should post examples but alieks might still be
working on the exercise and I don't want to spoil anybodies joy for my