Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python code In this lab, you will define functions which you will call from another function. A. In the file lab5.py, write a function named
python code
In this lab, you will define functions which you will call from another function. A. In the file lab5.py, write a function named distance() that takes four float parameters x1, 41, X2, 42, which represent the two points on the plane (X1, y1) and (x2, y2) and returns the distance between the two points. The distance D is given by this formula: D = (x2 - 1)2 + (y2 - y2). The template of the function is def distance(x1, yi, x2, y2): B. Write the usual main function that will read as input the four values x1, yi, x2, y2, one at a time from the user. They should be considered float values, although integer values may be given. For example, for reading xl you could use the usual: x1 = eval(input("Input x1: ")) It will then output the two points and the distance between them, as in this example: The distance between point (3, 4) and (5,6) is 2.8284271247461903 C. In the same file above main(, write another function even_or_odd that will take as parameter a float number x. If round(x) is an even number, it should output The given number x is closest to an the even number y. else, it should output The given number x is closest to an the odd number y. where x and y should be the actual values of the input and the rounded number, respectively. D. Add to the main() function so that after it outputs the distance between the two points, it calls the function even_or_odd(D), where parameter D is the distance between the two points. E. Make sure you include a header in Lab5.py, as always, along these lines: 5-1 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