Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- class Main():
- # def __init__(self):
- # super().__init__()
- def menu(self):
- print('1. Calculate the volume of a sphere')
- print('2. Calculate the Area of a Triangle')
- print('3. Show odds and their squares between 1-50')
- print('4. Quit')
- option = int(input("Please enter the number of an option you want to do: "))
- if option == 1:
- sphere = Main.sphere(self)
- elif option == 2:
- triangle = Main.triangle(self)
- elif option == 3:
- squares = Main.squares(self)
- elif option == 4:
- print("Thank you!!")
- option2 = str(input("Do you want to try again? "))
- if option2 == "yes" or option2 == "y" or option2 == "YES":
- Main.menu(self)
- elif option2 == "no":
- import sys
- print("Okay then")
- sys.exit()
- def sphere(self):
- radius = float(input('Please enter the radius of the circle: '))
- if radius > 0:
- volume = 4 / 3 * math.pi * radius * radius * radius
- print('Radius:', format(radius,'10.2f'))
- print('Volume:', format(volume,'10.2f'))
- else:
- print ('Do not enter 0 or lower')
- return radius
- def triangle(self):
- base = float(input('What is the base of the triangle? '))
- height = float(input('What is the height of the triangle? '))
- area = base * height * .5
- print('Height:', format(height, '15.2f'))
- print('Base:', format(base, '15.2f'))
- print('Triangle Area:', format(area, '15.2f'))
- return base, height, area
- def squares(self):
- for odds in range(1, 50, 2):
- root = math.sqrt(odds)
- print(odds, '\t', root)
- if __name__ == "__main__":
- main = Main()
- main.menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement