Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is my volume calculator program
- from volumes import * # imports the cubeVolume function, the pyramidVolume function, and the ellipsoidVolume function
- ## VARIABLES ##
- # list variables
- cubeList = []
- pyramidList = []
- ellipsoidList = []
- # variables from the given summarize function
- NEWLINE = "\n"
- DASH = "-"
- SPACE = " "
- # boolean variable that checks if testNumber input is a number
- isNotNum = True
- #
- ##
- testNumber = input("What test number do you want assigned for your calculations? ")
- if testNumber.isnumeric(): # if statement to test if input for testNumber is a number
- isNotNum = True # if testNumber is a number, the program will continue to shape
- else: # else statement if testNumber is NOT a number
- while isNotNum: # while loop that will continue if the user does not enter a number
- testNumber = input("That is an invalid input! Please enter a number to be assigned to your volume calculations. ")
- if testNumber.isnumeric():
- isNotNum = False
- shape = "" # "" is used to identify shape as a string
- while shape != "quit" or "q": # while the user does NOT input quit/q, this loop will ask the user for a shape
- shape = input("Please enter what shape you would like \nValid inputs are cube or c, pyramid or p, ellipsoid or e. Otherwise enter quit or q to stop ").replace(" ", "").lower()
- # while loop when user does not input valid input
- while shape != "cube" and shape != "c" and shape != "pyramid" and shape != "p" and shape != "ellipsoid" and shape != "e" and shape != "quit" and shape != "q":
- print("That is not a valid input. Please choose from cube/c, pyramid/p, ellipsoid/e. Otherwise enter quit/q to stop.")
- shape = input("Please enter what shape you would like \nValid inputs are cube/c, pyramid/p, ellipsoid/e or enter quit/q to stop: ").replace(" ", "").lower()
- if shape == "cube" or shape == "c": # if the user enters cube or c, the program will run this statement
- sideLength = float(input("Please enter the side length: "))
- print(" ") # this print statement helps format the program to not look so cluttered
- vol = cubeVolume(sideLength) # variable to store the return value from the function
- cubeList.append(vol) # .append(vol) adds the value of the calculation to the end of the cubeList in this case
- cubeList.sort() # .sort() will sort the values in the cubeList from smallest to highes
- elif shape == "pyramid" or shape == "p": # if the user enters pyramid or p, the program will run this statement
- baseLength = float(input("Please enter the base length: "))
- height = float(input("Please enter the height: "))
- print(" ")
- vol = pyramidVolume(baseLength, height)
- pyramidList.append(vol)
- pyramidList.sort()
- elif shape == "ellipsoid" or shape == "e": # if the user enters ellipsoid or e, the program will run this statement
- radius1 = float(input("Please enter the first radius length: "))
- radius2 = float(input("Please enter the second radius length: "))
- radius3 = float(input("Please enter the last radius length: "))
- print(" ")
- vol = ellipsoidVolume(radius1, radius2, radius3)
- ellipsoidList.append(vol)
- ellipsoidList.sort()
- else: # when the user enters quit/q, the program will show the results if there are any
- print("You have come to the end of your session. \nThe volumes of the shape(s) are shown below.")
- print(" ") # this print statement helps format the program to not look so cluttered
- if not cubeList and not pyramidList and not ellipsoidList: # if statement if the user didn't ask for any calculations
- print("You didn't ask for any calculations. \nThere are no calculated values.")
- quit(0) # this will stop the program when there are no calculated values
- else:
- if not cubeList: # if statement when there are no volume calculations for cubes
- print("Cube: There are no calculations.")
- elif cubeList:
- for i in cubeList: # this removes the [] in the list
- print("Cube:", "%.2f" % i) # this print statement will format the output to 2 decimal places
- if not pyramidList: # if statement when there are no volume calculations for pyramids
- print("Pyramid: There are no calculations.")
- elif pyramidList:
- for i in pyramidList:
- print("Pyramid:", "%.2f" % i)
- if not ellipsoidList: # if statement when there are no volume calculations for ellipsoids
- print("Ellipsoid: There are no calculations.")
- elif ellipsoidList:
- for i in ellipsoidList:
- print("Ellipsoid:", "%.2f" % i)
- quit(0) # this will stop the program when everything is done
- #
- # Assignment #2
- # Output of list elements for testing program
- #
- # Function summarize simply outputs the lists for each shape with 2 decimal place accuracy
- #
- # below is the summarize function given for assignment 2
- #
- def summarize(clist,plist,elist,testNumber):
- fname = "Asgn2TestCase" + str(testNumber)
- print()
- print("*** Creating output for test "+ str(testNumber))
- print()
- outf = open(fname,"w")
- output_list(clist,outf)
- output_list(plist,outf)
- output_list(elist,outf)
- outf.close()
- def output_list(lst,outfile):
- lngth = len(lst)
- if lngth > 0:
- for item in lst:
- str = "%6.2f" % item
- outfile.write(str+SPACE)
- outfile.write(NEWLINE)
- else:
- outfile.write(DASH+NEWLINE)
- summarize(cubeList, pyramidList, ellipsoidList, testNumber)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement