Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

Students also viewed these Databases questions