Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###################################################
- ## Name: Oliver Chapman ##
- ## Date of Creation: 10/12/2016 ##
- ## Description: A program that can calaculate ##
- ## various measurements depending ##
- ## on the shape selected. ##
- ## Versiom: 0.1 ##
- ###################################################
- ## Import modules, but give them a different identifier
- import math as m
- import os as o
- import sys as s
- import time as t
- def __init__(): ## Defines the main function of the program
- result = 0.0 ## Sets the result value to 0.0
- o.system('cls') ## Clears the screen
- ## Prints the options on the screen
- print("----====> Shape Calculator <====----")
- print("\nPlease select an option.")
- print("\n\n1) Area of a Circle\n\n2) Circumference of a Circle\n\n3) Area of a Rectangle\n\n4) Area of a Triangle\n\n5) Volume of a Cuboid\n\n6) Help\n\n0) Quit\n\n")
- try:
- option = int(input("Option: ")) ## Attempts to get an input from the user and store it in 'option'
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!") ## If the users input is invalid, display an error message
- t.sleep(3) ## Pauses the program for 'x' amount of seconds (x = seconds)
- __init__() ## Calls the __init__ function
- ## Checks to see what the user entered and handles it accordingly
- if option == 1:
- __cirArea(result) ## Call the __cirArea function with the result value passed (Call-by-reference)
- elif option == 2:
- __cirCircum(result)
- elif option == 3:
- __recArea(result)
- elif option == 4:
- __triArea(result)
- elif option == 5:
- __cubVol(result)
- elif option == 6:
- __help()
- elif option == 0:
- __quit()
- else:
- print("\n\n!! Please enter a number between 0 & 6. !!")
- t.sleep(3)
- __init__()
- def __cirArea(result):
- radius = 0.0 ## Sets the radius to 0.
- pi = m.pi ## Sets pi to the object pi from the math module
- o.system('cls')
- print("----====> Area of a Circle <====----")
- try:
- radius = float(input("\n\nRadius: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __cirArea(result)
- if radius >= 1 and radius <= 100: ## If the user inputted a number between 1 & 100
- result = radius * pi ## Calculate the result
- print("\n\nAnswer: ",result)
- wait = input("\n\nPress enter to continue... ") ## Wait for the user to continue
- __init__() ## Go back to the menu
- else:
- print("\n\n!! Please enter a number between 1 & 100. !!")
- t.sleep(3)
- __cirArea(result)
- def __cirCircum(result):
- radius = 0.0
- pi = m.pi
- o.system('cls')
- print("----====> Circumference of a Circle <====----")
- try:
- radius = float(input("\n\nRadius: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __cirCircum(result)
- if radius >= 1 and radius <= 100:
- result = pi * (radius * 2)
- print("\n\nAnswer: ",result)
- wait = input("\n\nPress enter to continue... ")
- __init__()
- else:
- print("\n\n!! Please enter a number between 1 & 100. !!")
- t.sleep(3)
- __cirCircum(result)
- def __recArea(result):
- length = 0.0 ## Sets the length to 0
- width = 0.0 ## Sets the width to 0
- pi = m.pi
- o.system('cls')
- print("----====> Area of a Rectangle <====----")
- try:
- length = float(input("\n\nLength: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __recArea(result)
- try:
- width = float(input("\n\nWidth: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __recArea(result)
- if length >= 1 and length <= 100 and width >= 1 and width <= 100:
- result = length * width
- print("\n\nAnswer: ",result)
- wait = input("\n\nPress enter to continue... ")
- __init__()
- else:
- print("\n\n!! Please enter a number between 1 & 100. !!")
- t.sleep(3)
- __recArea(result)
- def __triArea(result):
- base = 0.0 ## Sets the base to 0
- height = 0.0 ## Sets the height to 0
- o.system('cls')
- print("----====> Area of a Triangle <====----")
- try:
- base = float(input("\n\nBase: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __triArea(result)
- try:
- height = float(input("\n\nWidth: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __triArea(result)
- if base >= 1 and base <= 100 and height >= 1 and height <= 100:
- result = 0.5 * (base * height)
- print("\n\nAnswer: ", result)
- wait = input("Press enter to continue... ")
- __init__()
- else:
- print("\n\n!! Please enter a number between 1 & 100. !!")
- t.sleep(3)
- __triArea(result)
- def __cubVol(result):
- length = 0.0 ## Sets the length to 0
- width = 0.0 ## Sets the width to 0
- height = 0.0 ## Sets the height to 0
- o.system('cls')
- print("----====> Volume of a Cuboid <====----")
- try:
- length = float(input("\n\nLength: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __cubVol(result)
- try:
- width = float(input("\n\nWidth: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __cubVol(result)
- try:
- height = float(input("\n\nHeight: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __cubVol(result)
- if length >= 1 and length <= 100 and width >= 1 and width <= 100 and height >= 1 and height <= 100:
- result = 0.5 * (base * height)
- print("\n\nAnswer: ", result)
- wait = input("Press enter to continue... ")
- __init__()
- else:
- print("\n\n!! Please enter a number between 1 & 100. !!")
- t.sleep(3)
- __cubVol(result)
- def __quit():
- secs = 5
- uQuit = 'n'
- o.system('cls')
- print("----====> Quit <====----")
- try:
- uQuit = input("\n\nAre you sure you want to quit [Y/N]: ")
- uQuit = uQuit.upper() ## Sets the user input to uppercase
- except ValueError:
- print("\n\n!! Invalid Input Detected. !!")
- t.sleep(3)
- __quit()
- if uQuit == "Y":
- for counter in range(secs): ## Run until the counter is equivalent to secs variable
- o.system('cls')
- print("Closing in", secs,"...")
- secs = secs -1
- t.sleep(1)
- if secs == 0: ## If secs is 0, close the program
- print("\n\nGoodbye!")
- t.sleep(3)
- s.exit()
- elif uQuit == "N":
- __init__()
- else:
- print("\n\n!! Please enter either Y or N. !!")
- t.sleep(3)
- __quit()
- def __help():
- help = 0
- o.system('cls')
- print(" ----====> Help <====----")
- print("\nThis is the help menu. Here you can select\na calculation that you want help with.")
- print("\n\n1) Area of a Circle\n\n2) Circumference of a Circle\n\n3) Area of a Rectangle\n\n4) Area of a Triangle\n\n5) Volume of a Cuboid\n\n6) Main Menu")
- try:
- help = int(input("\n\nOption: "))
- except ValueError:
- print("\n\n!! Invalid Input Detected !!")
- t.sleep(3)
- __help()
- if help == 1:
- __cirArHelp()
- elif help == 2:
- __cirCiHelp()
- elif help == 3:
- __recArHelp()
- elif help == 4:
- __triArHelp()
- elif help == 5:
- __cubVoHelp()
- elif help == 6:
- __init__()
- else:
- print("\n\n!! Please enter a number between 1 & 6. !!")
- t.sleep(3)
- __help()
- def __cirArHelp():
- o.system('cls')
- print(" ----====> Area of a Circle <====-----")
- print("\nEnter the radius. The program will then square it\nand multiply it by pi.\nThe answer will be displayed in centimeters squared.")
- wait = input("\n\nPress enter to continue... ")
- __help()
- def __cirCiHelp():
- o.system('cls')
- print(" ----====> Circumference of a Circle <====-----")
- print("\nEnter the radius. The program will then double it\n& multiply it by pi.\nThe answerwill be displayed in centimeters squared.")
- wait = input("\n\nPress enter to continue... ")
- __help()
- def __recArHelp():
- o.system('cls')
- print(" ----====> Area of a Rectangle <====-----")
- print("\nEnter the length & width. The program will then multiply\nthe length & width together.\nThe answer will be displayed in centimeters squared.")
- wait = input("\n\nPress enter to continue... ")
- __help()
- def __triArHelp():
- o.system('cls')
- print(" ----====> Area of a Triangle <====-----")
- print("\nEnter the base & height. The program will then \nmultiply the base & height and halve it.\nThe answer will be displayed in centimeters squared.")
- wait = input("\n\nPress enter to continue... ")
- __help()
- def __cubVoHelp():
- o.system('cls')
- print(" ----====> Volume of a Cuboid <====-----")
- print("\nEnter the base, width & height.\nThe program will then square it\n& multiply all three numbers together.\nThe answer will be displayed in centimeters cubed.")
- wait = input("\n\nPress enter to continue... ")
- __help()
- __init__()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement