Python Forum
Someone please look at this and tell me what i'm doing wrong
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Someone please look at this and tell me what i'm doing wrong
#1
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
Reply
#2
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
Reply
#3
(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)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020