def test_volume(self): self.assertAlmostEqual(volume(self.radius), 904.78, places=2) self.assertEqual(volume('bleen'), 0)
#!/usr/bin/env python # -*- coding: utf8 -*- """ spheretest.py - Chapter 14, exercise 1 """ #from sphere import * import sphere print 'Enter the radius :' radius = int(input()) print 'The area is: ' + str(sphere.area(radius)) print 'The volume is: ' + str(sphere.volume(radius))
#from sphere import * import sphere print("Enter the radius of the sphere: ") radius = int(input()) #print("The area is " + str(area(radius))) #print("The volume is " + str(volume(radius))) print("The area is " + str(sphere.area(radius))) print("The volume is " + str(sphere.volume(radius)))
# sphereTest # C:\Users\lenovo\Desktop\2020\2020DeveloPython sample1 = ''' from sphere import * print ("enter the radius of the sphere") radius = int(input()) print ("the area is" + str(area(radius))) print ("the volume us " + str(volume(radius))) ''' #sample2 import sphere print ("enter the radius of the sphere") radius = int(input()) print ("the area is" + str(sphere.area(radius))) print ("the volume us " + str(sphere.volume(radius)))
#from sphere import * import sphere radius=int(input("Enter radius of a sphere ")) print "Area of sphere is "+ str(sphere.area(radius)) print "Volum of sphere is "+ str(sphere.volume(radius))
def main(): # The choice variable controls the loop # and holds the user's menu choice. choice = 0 while not (choice == 5): # display the menu. display_menu() # Get the user's choice. choice = int(input('Enter your choice: ')) # Perform the selected action. if choice == 1: r = float(input("Enter the circle's radius: ")) print('The area is {:.3f}.'.format(circle.area(r))) elif choice == 2: radius = float(input("Enter the circle's radius: ")) print('The circumference is {:.3f}'.\ format(circle.circumference(radius))) elif choice == 3: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print("The area is {:.3f}".format(rectangle.area(width, length))) elif choice == 4: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print('The perimeter is {:.3f}'.\ format(rectangle.perimeter(width, length))) elif choice == 5: base = float(input("Enter triangle's base length: ")) height = float(input("Enter the triangle's height: ")) print("The area is: {:.3f}".format(triangle.area(height, base))) elif choice == 6: side_a = float(input("Enter the length of the side a: ")) side_b = float(input("Enter the length of the side b: ")) side_c = float(input("Enter the length of the side c: ")) print("The perimeter of the triangle is: {:.3f}".\ format(triangle.perimeter(side_a, side_b, side_c))) elif choice == 7: radius = float(input("Enter the sphere's radius: ")) print("The surface area of the sphere is: {:.3f}".\ format(sphere.surface(radius))) elif choice == 8: height = float(input("Enter the sphere's height: ")) radius = float(input("Enter the sphere's radius: ")) print("The volume of the sphere is: {:.3f}".\ format(sphere.volume(height,radius))) elif choice == 9: height = float(input("Enter the cylinder's height: ")) radius = float(input("Enter the cylinder's radius: ")) print("The surface area of the cylinder is: {:.3f}".\ format(cylinder.surface(height, radius))) elif choice == 10: height = float(input("Enter the cylinder's height: ")) radius = float(input("Enter the cylinder's radius: ")) print("The volume of the cylinder is: {:.3f}".\ format(cylinder.volume(height, radius))) elif choice == 0: print("Exiting the program...") else: print("Error: invalid selection.")