[Tutor] i have a question???

Jacob S. keridee at jayco.net
Fri Feb 4 01:23:25 CET 2005


Sorry, over paranoid. ;-)
Jacob



>>    num = num + math.pi/6.0   ## Don't forget .0 or you'll get an integer
>
> the division operator returns a float when either of the operands are
> floats -- in this case math.pi is, so you don't have to worry about
> passing it 6.0 instead of 6
>
>>>> import math
>>>> math.pi
> 3.1415926535897931
>>>> math.pi / 6
> 0.52359877559829882
>
>>>> type(math.pi)
> <type 'float'>
>>>> type(6)
> <type 'int'>
>>>> type(6.0)
> <type 'float'>
>
>
> mike
>
>
>
> On Thu, 3 Feb 2005 16:04:25 -0500, Jacob S. <keridee at jayco.net> wrote:
>> >From what I understand, range() no longer allows you to use floats as
>> arguments. (Or it gives you a deprication warning)
>> This tutorial must be old.
>>
>> Not the only way, but.
>>
>> import math
>> num = 0
>> while num <= 2*math.pi:
>>     ## Do stuff to figure pi/6 things
>>
>>     num = num + math.pi/6.0   ## Don't forget .0 or you'll get an integer
>> result.
>>     print ## Result thingy
>>
>> Another way is to use Numarry (Numeric) arange() but that takes extra 
>> work.
>> ;-)
>> Jacob
>>
>>
>> > This is from a tutorial
>> >
>> > "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."
>> >
>> > Range won't let me use pi/6 as an incremator
>> > is there some other way i can accomplish this task
>> > im new to programming so all the help i can get is
>> > greatly appreciated.
>> > NI!
>> > alex
>> >
>> >
>> >
>> >
>> > __________________________________
>> > Do you Yahoo!?
>> > The all-new My Yahoo! - What will yours do?
>> > http://my.yahoo.com
>> > _______________________________________________
>> > Tutor maillist  -  Tutor at python.org
>> > http://mail.python.org/mailman/listinfo/tutor
>> >
>> >
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
> 



More information about the Tutor mailing list