Question



This lab covers: arrays functions input exception handling Question 1 The purpose of this question is to write a python progr
Write a function that begins with the header def yonEllipse (a, b, xValues) : This function is given the lengths of the major
Enter the length of the major axis: Missing input! Enter the length of the major axis: hello hello is not a number! Enter tplease there are some specific instructions on the question so i would greatly appreciate if they are followed . thank you very much for your time
This lab covers: arrays functions input exception handling Question 1 The purpose of this question is to write a python program (script) that manipulates arrays using vector arithmetic. You will compute the values of points The ellipse has a major axis whose length is a and a minor axis whose length is b. For any point (xy) on the ellipse the following should be true. ellipse. on an x2 a b2 Write a function that begins with the header: def getNumber (prompt ) : The function repeatedly asks for a number (either a float or an int), by displaying the prompt, until the user enters a valid number. The function returns the number entered by the user. Hint: Strip the leading and trailing whitespace from the input from the user If value is the value returned by input the function must perform the following tests: if value is not a float or an int display the value of value and the message 'is not a number! if eval(value, [1. ) causes an if value is an empty string (that is the user did not type anything in and pressed return/enter) display the message Missing input! exception display the message Invalid input! Note: You should be able to modify a function from lab 6 to do this. 1 3 Page
Write a function that begins with the header def yonEllipse (a, b, xValues) : This function is given the lengths of the major and minor axes and an array of X values. It must compute and return a new array of Y values using vector arithmetic where each element in the new array is computed using the formula y=b1- where a is the length of the major axis, b is the length of the minor axis and x is an element of the array of x values. Each value of (xy) is a point on the ellipse. Note: You must NOT use for or while in this function. Write a function that begins with the header: def verifyPoints (a, b, xvalues, yValues): This function uses vector arithmetic to compute and return an array where each element is True if 1-x a b for each corresponding pair of x and y values in the arrays xValues and yValues, otherwise the element is False. Note: You must NOT for or while in this function. use Write a function that begins with the header: def main(): This function calls getNumber three times to get the length of the major axis (a), the length of the minor axis (b), and the number of points along the major axis. The array of x values is created using the linspace function. For example if a 10.0 and the number of points along the major axis is 6 the array of x values is [0., 2, 4, 6, 8, 10.. Call yOnEllipse and verifyPoints to create two new arrays. Display the corresponding values of the arrays in three columns under an appropriate heading as shown in the sample output. The main program (not to be confused with the function main) should contain any import statements needed, the definitions of the functions and the statement main(). A sample run of the program is shown on the next page. In the column labeled 'On Ellipse all of the values should be True, why are some of them False?
Enter the length of the major axis: Missing input! Enter the length of the major axis: 'hello' hello is not a number! Enter the length of the major axis: stuff Invalid input! Enter the length of the major axis: 10 Enter the length of the minor axis: 5 Enter the number of points along the major axis: 20 On Ellipse X 0.00 0.53 5.0000000000 4.9930699897 4.9722220073 4.9372797472 4.8879409529 4.8237638894 True True False False 1.05 1.58 True 2.11 False False 2.63 4.7441464151 3.16 4.6482951928 4.5351810367 True 3.68 True 4.21 4.4034738239 True 4.74 False False 4.2514459004 5.26 5.79 4.0768245750 True 3.8765578586 6.32 True 3.6464227528 6.84 7.37 7.89 8.42 3.3803243628 3.0689220499 2.6965659910 True True True True 2.2329687827 8.95 True 9,47 10.00 1.6007269817 True 0.0000000000 Programmed by Stew Dent. Date: Sat oct 27 10:05:56 2018 End of processing.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# module to genereate the random xvalues
import random
# to compute the square root value
import math
# method to read the number
def getNumber(msg):
   print(msg)
   x = input().strip()
   if(x==""):
       print("Missing input")
       getNumber(msg)
   else:
       try:
           x = float(x)
       except:
           print("Invalid input")
           getNumber(msg)
   return x
# method to compute the yvalues
def yOnEclipse(a,b,xValues):
   xsqrd = [i**2 for i in xValues]
   y=[]
   y = [b*(math.sqrt(1-(x**2/a**2))) for x in xValues]
   return y
# method to verify the eclipse
def verifyPoints(a,b,xValues,yValues):
   check =[]
   check = [(x**2/a**2)+(y**2/b**2)==1 for x,y in zip(xValues,yValues)]
   return check
# main method
def main():
   msg = "Enter the length of major Axis"
   a = getNumber(msg)
   msg = "Enter the length of minor axis"
   b= getNumber(msg)
   msg = "Enter number of point along major axis"
   n = getNumber(msg)
   # uniform() method to generate the random floating point numbers in the given range
   xValues =[round(random.uniform(0,a),2) for i in range(int(n))]
   yValues = yOnEclipse(a,b,xValues)
   check = verifyPoints(a,b,xValues,yValues)
   # ouput the values
   print("X","Y","OnEclipse",sep="\t")
   for x,y,c in zip(xValues,yValues,check):
       print(x,y,c,sep="\t")
# called when executed directly without importing module
if __name__ == '__main__':
   main()

X Command Prompt c:NUsers DellNDesktop>pyt hon eclipse.py Enter the length of major Axis Enter the length of minor axis 5 Ent

Add a comment
Know the answer?
Add Answer to:
please there are some specific instructions on the question so i would greatly appreciate if they...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help code in c++ and use the answers you get from question 1 and 2...

    Please help code in c++ and use the answers you get from question 1 and 2 into the 3rd answer! Question 1 is first, question 2 is in the middle, question 3 is last Input Array (10 pts) te a function only (no main) that takes an array of doubles as a parameter as well as another integer rray. Create a for loop that asks the user to input any real number between-100 and r each element of the array....

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • Thank you! /*Lab 8 : Practicing functions and arrays Purpose: */ #include<iostream> #include<fstream> using namespace std;...

    Thank you! /*Lab 8 : Practicing functions and arrays Purpose: */ #include<iostream> #include<fstream> using namespace std; int read_function(int array[], int, int); int main() { int array[300], numba; read_function(array[300]); cout << "Enter a whole number between 2-20: " << endl; cin >> numba; read_function(numba); return 0; } int read_funtion (int arr[300], int num, int Values) { int sum=0; ifstream array_file; array_file.open("Lab8.dat"); for(int i=0; i < 300; i++) {   array_file >> arr[i];   cout << arr[i];   sum += i; } cout << sum;...

  • In this lab, you will create a program to help travelers book flights and hotel stays that will b...

    In this lab, you will create a program to help travelers book flights and hotel stays that will behave like an online booking website. The description of the flights and hotel stays will be stored in two separate String arrays. In addition, two separate arrays of type double will be used to store the prices corresponding to each description. You will create the arrays and populate them with data at the beginning of your program. This is how the arrays...

  • C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible;...

    C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...

  • AND logic gate simulation in Python: Please fix the code below so that it efficiently performs...

    AND logic gate simulation in Python: Please fix the code below so that it efficiently performs the operation of the AND logic gate in Python. (Leave comments in the edited code about what you changed) #if both values are 1, return true, other wise return false print ("Logic Gate Simulation: AND gate") def AND(x, y):     if x == True and y == True:         return True        else:         return False    def main():     x = bool(input("Please...

  • Please follow the instructions below to create a code. The instructions are broken down into a...

    Please follow the instructions below to create a code. The instructions are broken down into a few steps. Create the following functions along with a driver for each one confirming it works. The driver needs to test the function with at least 5 different inputs, although more is always better. Be sure to use the function display_startup_banner( ) in all of your drivers. Please create separate files for each code. That is, if you're creating a function called learning_online_is_a_trip( )...

  • public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which...

    public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which does the following: In the main method: Use a for loop which repeats three times. Within the loop, a. prompt the user to enter the base of the triangular prism and store the value in a double array called base b. prompt the user to enter the corresponding height and store the value in a double array called height c. prompt the user to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT