Python Forum

Full Version: Someone please look at this and tell me what i'm doing wrong
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i put this into the UI:
def volume(h, r):
    return (h*(r**2)*(22/7))/3
print volume(4, 4)


but 64 is returned but nothing is printed.
although when i replace the variables *ONLY* with the same numbers (4) and put it in the calculator, i get 67.04. what am i doing wrong. is it me or python? please help.

im using version 2.7.10 on repl.it btw

i tried it on version 3....still never got correct results
This is in python 3 but this should work
def volume(h, r):
    print (( h * ( r**2 ) * ( 22 / 7)) / 3)
volume(4,4)
Output:
67.04761904761905
(Feb-24-2018, 04:28 AM)NGOtaku Wrote: [ -> ]but 64 is returned but nothing is printed.
the code is fine. how do you know it returns 64 if it doesn't print.
In python 2 it should print 64, in python3 (you need to add braces to make the print function, not statement) it should print 67.04761904761905

in python when you divide two integers, you get again integer (that is so called floor division)