Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Simple Python Program. The LeibnizClass need to only have class LeibnizPIClass and all the other instance methods such as such as areaC, CircleC, and VolumeS
Simple Python Program.
The LeibnizClass need to only have class LeibnizPIClass and all the other instance methods such as such as areaC, CircleC, and VolumeS should be under one class LeibnizPIClass and not seperate classes for each instance method. Program should work as it is working now with these changes. All of the instance methods are supposed to be e added to the existing class (LeibnizPIClass)
LeibnizClass.py
class LeibnizPIClass: pi = 0.0 '''Please enter the number of values to be calculated for Pi:''' def __init__(self, user_input): '''comment''' denominator = 1 numerator = 4 counter = 0 while counter < user_input: nextterm = numerator/denominator * (-1) **counter self.pi += nextterm denominator +=2 counter += 1 class AreaCircle: # create class to calculate the Area Circle def areaC(f1, radius): AreaCircle=f1 * radius * radius print("Area Circle= " + "%.2f" %AreaCircle) class CircleCircumference: # create class to calculate the Circle Circumference def CircleC(f1,radius): CircleCircumference=2 * f1 * radius print("Circle Circumference= "+ "%.2f" % CircleCircumference) class VolumeOfSphere: # create class to calculate the Volume of Sphere def VolumeS(f1,radius): VolumeOfSphere=(4/3) * f1 * radius * radius print("Volume Of Sphere= " + "%.2f" %VolumeOfSphere)
LeibnizProgram.py
import LeibnizClass 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 A to run the program again. " "Press Enter to end the program.") runagain = input() if runagain == "A": main() def main(): """This function controls the main thread of the program.""" print("Please enter the number of values to be calculated for Pi: ") response = input() try: user_input = int(response) except ValueError: errorMessages() else: if user_input <= 0: errorMessages() else: f = LeibnizClass.LeibnizPIClass(user_input) print("PI value is: " + str(f.pi)) f1=f.pi #store the pi value to f1 print("Please enter the Radius") r=float(input()) AreaCircle=LeibnizClass.AreaCircle.areaC(f1,r) #this function Calculate the Area of Circle CircleCircumference=LeibnizClass.CircleCircumference.CircleC(f1,r) #this function Calculate the Circle Circumference VolumeOfSphere=LeibnizClass.VolumeOfSphere.VolumeS(f1,r) #this function Calculate the Volume Of Sphere ending() main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started