Question: use list in this python question The purpose of this question is to write a complete Python program that computes the approximate circumference of an
use list in this python question
The purpose of this question is to write a complete Python program that computes the approximate circumference of an ellipse. The ellipse is defined by the lengths of the semi-major and semi-minor axes.
Write a function that begins with the following header:
def getPositiveNumber(prompt):
Call this function to get all input from the user. Valid input is either an int greater than or equal to zero or a float greater than or equal to zero. The function displays the prompt to tell the user what to enter. If the user does not enter valid input display the appropriate error message as described below and display the prompt again asking for more input from the user. Repeat this until the user enters valid input. When the user enters valid input return that input.
Error situations:
1. If the user presses enter/return without entering anything display the message 'Missing input!'
2. If the input causes an exception when passed to eval display the value of the input and the message 'is not valid!'
3. If the input is neither an int nor a float display the value of the input and the message 'is not a number!'
4. If the input is less than zero display the value of the input and the message 'is less than zero!'
Write a function that begins with the following header: def computeXcoordinates(a, intervals):
Given the value of a, the length of the semi-major axis, and the number of intervals create a list of equally spaced X coordinates from x = 0 to x = a. The first element in the list is 0 and the last element in the list is a. The number of X coordinates in the list is intervals + 1. Return the list of x coordinates.
Note: You must use list comprehension to create the list of X coordinates
Write a function that begins with the following header:
def computeYcoordinates (a, b, xValues):
Given the values of a, the length of the semi-major axis, b, the length of the semiminor axis and a list of X coordinates named xValues this function creates a list of Y coordinates using equation 1. There will be one Y coordinate for each X coordinate. Return the list of Y coordinates.
equation
Note: You must use list comprehension to create the list of Y coordinates.
Write a function that begins with the following header:
def calcCircumference(a, b, intervals):
Call computeXcoordinates to get the list of X coordinates and then call computeYcoordinates to get the list of corresponding Y coordinates. Use these two lists to compute the approximate circumference of an ellipse using the method described in class. Display the approximate circumference to 14 decimal places using exponential format. See the sample run of the program for the exact format of the output.
This function does not return a value.
The main program does the following:
1. Using string replication display a line of dashes.
2. Display a message indicating that zero may be entered after any prompt to terminate the program.
3. In a loop:
3.1 call getPositiveNumber to input the value of a, the length of the semi-major axis, as a float, if the value returned by getPositiveNumber is equal to 0 exit from the loop
3.2call getPositiveNumber to input the value of b, the length of the semi-minor axis, as a float, if the value returned by getPositiveNumber is equal to 0 exit from the loop
3.3 call getPositiveNumber to input the integer number of intervals, if the value returned by getPositiveNumber is equal to 0 exit from the loop
3.4 use the Timer and timeit functions from the timeit module to calculate the time it takes to compute the circumference of the ellipse.
3.5 display the time it took to compute circumference of the ellipse to 3 decimal places, see the sample output for the exact format of the output
4.Call displayTerminationMessage to display the termination message.
To use the Timer and timeit functions from the timeit module to calculate the time it takes to compute the circumference of the ellipse cut and paste the following statements into your program:
t = timeit.Timer('calcCircumference(a, b, intervals)',
'from __main__ import calcCircumference, a, b, intervals')
computeTime = t.timeit(1)
print("Compute time using lists is %.3f seconds." % computeTime)
There are two underscores before and after the word main in the statements given above.
To use the Timer and timeit functions import the timeit module.
the sample run of the program is shown below:
To terminate the program enter 0 after any prompt.
Enter the length of the semi-major axis in cm (> 0):
Missing input!
Enter the length of the semi-major axis in cm (> 0): sdsfg
sdsfg is not valid!
Enter the length of the semi-major axis in cm (> 0): True
True is not a number!
Enter the length of the semi-major axis in cm (> 0): -1
-1 is less than zero!
Enter the length of the semi-major axis in cm (> 0): 10.25
Enter the length of the semi-minor axis in cm (> 0): 7.75
Enter the number of intervals (> 0): 10000000
The approximate circumference of the ellipse is 5.68217058429445e+01 cm.
Compute time using lists is 7.271 seconds.
Enter the length of the semi-major axis in cm (> 0): 0
y = b* V1 - (x/a)2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
