Question: Write a program which imports unittest and then uses it to verify all the methods of the class which you wrote for Homework Assignment 4.

 Write a program which imports unittest and then uses it toverify all the methods of the class which you wrote for HomeworkAssignment 4. The program and class for homework 4 is in the

Write a program which imports unittest and then uses it to verify all the methods of the class which you wrote for Homework Assignment 4.

The program and class for homework 4 is in the screenshots above and the scripts below.

CLASS

class LeibenizClass: """A Class for use with Leibeniz formula""" # Attributes results = ""

# methods def __init__(self,x): """Creates a string with Leibeniz Formula""" a = 0 counter = 0 max_counter = x

for i in range(max_counter): a = a + ((-1) ** (i)) * (1 / (2 * i + 1)) self.results = str(a*4)

def Circumference(self, radius): """Calculate Circumference of Circle""" pi = float(self.results) return 2*pi*radius

def Area(self, radius): """Calculate Area of Circle""" pi = float(self.results) return pi*pow(radius, 2)

def Volume(self, radius): """Calculate Volume of Solid""" pi = float(self.results) return (4/3)*pi*pow(radius, 3)

def Surface(self, radius): """Calculate Surface of Solid""" pi = float(self.results) return 4*pi*pow(radius, 2)

PROGRAM

import KnoxHomework4Class

def errorMessages(): """This function contains the reusable error messages.""" print("You entered an invalid value. You must enter a positive integer.") main()

def ending(): """Allows the user to run the program again or terminate it.""" print(" " "Type y to run the program again. " "Press Enter to end the program.") runagain = input().lower() if runagain == "y": main() else: exit(0) def writeResultToFile(filename, obj, radius): file = open(filename, 'w') print("PI: ", obj.results, file=file) print("Circumference: ", obj.Circumference(radius), file=file) print("Area: ", obj.Area(radius), file=file) print("Volume: ", obj.Volume(radius), file=file) print("Surface: ", obj.Surface(radius), file=file) file.flush() file.close()

def readResultFromFile(filename): with open(filename) as f: for line in f.readlines(): print(line.strip())

def main(): """This function controls the main thread of the program.""" filename='output.txt' print("Please enter the number of values to be calculated:") response = input() try: max_counter = int(response) except ValueError: errorMessages() else: if max_counter

main()

import KnoxHomework4Class def errorMessages () : "This function contains the reusable error messages." print ("You entered an invalid value. You must enter a positive integer.") main() def ending(): "Allows the user to run the program again or terminate it.""" print(" " "Type y to run the program again. " "Press Enter to end the program.") runagain = input().lower() if runagain == "y": main() else: exit (0) writeResultToFile (filename, obj, radius): file = open(filename, 'w') print ("PI: ", obj.results, file=file) print ("Circumference: ", obj.Circumference (radius), file=file) print ("Area: ", obj.Area (radius), file=file) print ("Volume: ", obj. Volume (radius), file=file) print ("Surface: ", obj.Surface (radius), file=file) file. flush() file.close() def readResult FromFile (filename) : with open (filename) as f: for line in f.readlines (): print (line.strip ( ) def main(): "" "This function controls the main thread of the program." filename='output.txt' print("Please enter the number of values to be calculated:") response = input () try: max_counter = int (response) Del IdIHU! "F"This function controls the main thread of the program." filename='output.txt' print("Please enter the number of values to be calculated:") response = input () try: max counter = int (response) except ValueError: errorMessages () else: if max counter

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!