Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
I'm stuck. I need my program to round the end solution to 2 decimal places but 
cant figure it out. Can someone help? I've been trying between printf and 
round() but cant seem to get either to work. Python 3.5 is what I'm using.
import math

print("This program will calculate the surface area and volume of a 
3-dimensional cone: ")
print()
print()
r = input("What is the radius in feet? (no negatives): ")
h = input("What is the height in feet? (no negatives): ")
r = float(r)
h = float(h)
if r > 0 and h > 0:

   surfacearea = math.pi*r**2+r*math.pi*(math.sqrt(r**2+h**2))
   volume = (1/3)*math.pi*r**2*h



   print()
   print("Your Answer is:")
   print()

   print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", 
volume, "\nand surface area of : ", surfacearea,)
else:
print("No negatives allowed, try again.")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot...@gmail.com wrote:
> The following works:
> 
> import math
> 
> print("This program will calculate the surface area and volume of a 
> 3-dimensional cone: ")
> print()
> print()
> r = input("What is the radius in feet? (no negatives): ")
> h = input("What is the height in feet? (no negatives): ")
> r = float(r)
> h = float(h)
> if r > 0 and h > 0:
> 
> surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 
> 2))
> volume = (1 / 3) * math.pi * r ** 2 * h
> 
> print()
> print("Your Answer is:")
> print()
> 
> print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : 
> ", round(volume,2), "\nand surface area of : ",
>   round(surfacearea,2), )
> else:
> print("No negatives allowed, try again.")

Tried this but it doesn't seem to work. It still prints out all of the decimals 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
On Wednesday, December 6, 2017 at 9:03:27 PM UTC-5, ssghot...@gmail.com wrote:
> On Thursday, December 7, 2017 at 12:39:38 PM UTC+11, nick martinez wrote:
> > On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot...@gmail.com 
> > wrote:
> > > The following works:
> > > 
> > > import math
> > > 
> > > print("This program will calculate the surface area and volume of a 
> > > 3-dimensional cone: ")
> > > print()
> > > print()
> > > r = input("What is the radius in feet? (no negatives): ")
> > > h = input("What is the height in feet? (no negatives): ")
> > > r = float(r)
> > > h = float(h)
> > > if r > 0 and h > 0:
> > > 
> > > surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h 
> > > ** 2))
> > > volume = (1 / 3) * math.pi * r ** 2 * h
> > > 
> > > print()
> > > print("Your Answer is:")
> > > print()
> > > 
> > > print("A cone with radius", r, "\nand height of", h, "\nhas a volume 
> > > of : ", round(volume,2), "\nand surface area of : ",
> > >   round(surfacearea,2), )
> > > else:
> > > print("No negatives allowed, try again.")
> > 
> > Tried this but it doesn't seem to work. It still prints out all of the 
> > decimals
> 
> This is the output from the code above (Working):
> 
> What is the radius in feet? (no negatives): >? 2
> What is the height in feet? (no negatives): >? 4
> Your Answer is:
> A cone with radius 2.0 
> and height of 4.0 
> has a volume of :  16.76 
> and surface area of :  40.67

interesting, what version of python are you using? Tried it multiple times and 
it still isn't working.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
On Wednesday, December 6, 2017 at 9:32:27 PM UTC-5, nick martinez wrote:
> On Wednesday, December 6, 2017 at 9:03:27 PM UTC-5, ssghot...@gmail.com wrote:
> > On Thursday, December 7, 2017 at 12:39:38 PM UTC+11, nick martinez wrote:
> > > On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot...@gmail.com 
> > > wrote:
> > > > The following works:
> > > > 
> > > > import math
> > > > 
> > > > print("This program will calculate the surface area and volume of a 
> > > > 3-dimensional cone: ")
> > > > print()
> > > > print()
> > > > r = input("What is the radius in feet? (no negatives): ")
> > > > h = input("What is the height in feet? (no negatives): ")
> > > > r = float(r)
> > > > h = float(h)
> > > > if r > 0 and h > 0:
> > > > 
> > > > surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + 
> > > > h ** 2))
> > > > volume = (1 / 3) * math.pi * r ** 2 * h
> > > > 
> > > > print()
> > > > print("Your Answer is:")
> > > > print()
> > > > 
> > > > print("A cone with radius", r, "\nand height of", h, "\nhas a 
> > > > volume of : ", round(volume,2), "\nand surface area of : ",
> > > >   round(surfacearea,2), )
> > > > else:
> > > > print("No negatives allowed, try again.")
> > > 
> > > Tried this but it doesn't seem to work. It still prints out all of the 
> > > decimals
> > 
> > This is the output from the code above (Working):
> > 
> > What is the radius in feet? (no negatives): >? 2
> > What is the height in feet? (no negatives): >? 4
> > Your Answer is:
> > A cone with radius 2.0 
> > and height of 4.0 
> > has a volume of :  16.76 
> > and surface area of :  40.67
> 
> interesting, what version of python are you using? Tried it multiple times 
> and it still isn't working.

Never mind its working now, just had to change something up real quick, thank 
you.
-- 
https://mail.python.org/mailman/listinfo/python-list