Advertisement
los1234

Here

Feb 23rd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import math
  2.  
  3.  
  4. class Main():
  5.  
  6. # def __init__(self):
  7.  
  8. # super().__init__()
  9.  
  10. def menu(self):
  11. print('1. Calculate the volume of a sphere')
  12. print('2. Calculate the Area of a Triangle')
  13. print('3. Show odds and their squares between 1-50')
  14. print('4. Quit')
  15. option = int(input("Please enter the number of an option you want to do: "))
  16. if option == 1:
  17. sphere = Main.sphere(self)
  18. elif option == 2:
  19. triangle = Main.triangle(self)
  20. elif option == 3:
  21. squares = Main.squares(self)
  22. elif option == 4:
  23. print("Thank you!!")
  24. option2 = str(input("Do you want to try again? "))
  25. if option2 == "yes" or option2 == "y" or option2 == "YES":
  26. Main.menu(self)
  27. elif option2 == "no":
  28. import sys
  29. print("Okay then")
  30. sys.exit()
  31.  
  32. def sphere(self):
  33. radius = float(input('Please enter the radius of the circle: '))
  34. if radius > 0:
  35. volume = 4 / 3 * math.pi * radius * radius * radius
  36. print('Radius:', format(radius,'10.2f'))
  37. print('Volume:', format(volume,'10.2f'))
  38. else:
  39. print ('Do not enter 0 or lower')
  40.  
  41. return radius
  42.  
  43. def triangle(self):
  44. base = float(input('What is the base of the triangle? '))
  45. height = float(input('What is the height of the triangle? '))
  46. area = base * height * .5
  47. print('Height:', format(height, '15.2f'))
  48. print('Base:', format(base, '15.2f'))
  49. print('Triangle Area:', format(area, '15.2f'))
  50. return base, height, area
  51.  
  52. def squares(self):
  53. for odds in range(1, 50, 2):
  54. root = math.sqrt(odds)
  55. print(odds, '\t', root)
  56.  
  57.  
  58. if __name__ == "__main__":
  59. main = Main()
  60. main.menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement