[Tutor] Division question, simple
Sean 'Shaleh' Perry
shalehperry@attbi.com
Mon, 17 Dec 2001 13:11:59 -0800 (PST)
On 17-Dec-2001 Frank Peavy wrote:
> In the interactive mode:
> >>> 75/100
> 0
> >>> float(75/100)
> 0.0
> >>> x = 75
> >>> y = 100
> >>> float(x/y)
> 0.0
> >>> float(75)/float(100)
> 0.75
>
> In order to get 75%, I almost need to know my desired result, before I have
> my values. Is this how everyone handles simple division in Python?
>
> When I am dividing 100 by 25 the result is an integer of 4, fine.
> But, when I don't know my second value is 25... maybe it is 33, then my
> result would be 3.33333
> BUT, Python gives me 3. How does everyone else handle this?
>
if I know I want a decimal, I cast one number to a float.