I need your help on my Python programming course with the function for the hypotenuse. I've included the guide on what I need for 6,8,10 hypotenuse.  These are the integers I chose myself to make a new function for my hypotenuse. I need it for the function instructed in the assignment, please. The example hypotenuse function as follows; def distance(x1,y1,x2,y2):        return 0.0 to the test new function, call it with sample arguments: >>>distance(1,2,4,6) 0.0 I would like to choose the horizontal distance at 6 and the vertical distance at 8 that way the result is 10, the hypotenuse of a 6-8-10 triangle.  At this point we have confirmed that the function is syntactically correct, and we can start adding code to the body. A reasonable next step is to find the differences  x2 -x1 and y2 -y1. The next version stores those values in temporary variables and prints them. def distance(x1, y1, x2,y2):        dx = x2-x1        dy = y2-y1        print('dx is',dx)        print('dy is',dy)        return 0.0 If the function is working, it should display dx is 6 and dy is 8. If so, we know that the function is getting the right arguments and performing the first computation correctly. If not, there are only a few lines to check. Next we compute the sum of squares of dx and dy: def distance(x1, y1,x2,y2):        dx = x2-x1        dy = y2-y1        dsquared = dx**2 + dy**2        print('dsquared is ', dsquared)        return 0.0 Again, you would run the program at this sage and check the output (which should be 10). Finally, you can use math.sqrt to compute and return the result: def distance(x1,y1,x2,y2):        dx = x2 - x1        dy = y2-y1        dsquared = dx**2 + dy**2        result = math.sqrt(dsquared)        return result if that works correctly, you are done. Otherwise, you might want to print the value of result before the return statement. The final version of the function doesn't display anything when it runs; it only returns a value. The prints statements we wrote are useful for debugging, but once you get the function working, you should remove them.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need your help on my Python programming course with the function for the hypotenuse. I've included the guide on what I need for 6,8,10 hypotenuse.  These are the integers I chose myself to make a new function for my hypotenuse. I need it for the function instructed in the assignment, please.

The example hypotenuse function as follows;

def distance(x1,y1,x2,y2):

       return 0.0

to the test new function, call it with sample arguments:

>>>distance(1,2,4,6)

0.0

I would like to choose the horizontal distance at 6 and the vertical distance at 8 that way the result is 10, the hypotenuse of a 6-8-10 triangle. 

At this point we have confirmed that the function is syntactically correct, and we can start adding code to the body. A reasonable next step is to find the differences  x2 -xand y-y1. The next version stores those values in temporary variables and prints them.

def distance(x1, y1, x2,y2):

       dx = x2-x1

       dy = y2-y1

       print('dx is',dx)

       print('dy is',dy)

       return 0.0

If the function is working, it should display dx is 6 and dy is 8. If so, we know that the function is getting the right arguments and performing the first computation correctly. If not, there are only a few lines to check.

Next we compute the sum of squares of dx and dy:

def distance(x1, y1,x2,y2):

       dx = x2-x1

       dy = y2-y1

       dsquared = dx**2 + dy**2

       print('dsquared is ', dsquared)

       return 0.0

Again, you would run the program at this sage and check the output (which should be 10). Finally, you can use math.sqrt to compute and return the result:

def distance(x1,y1,x2,y2):

       dx = x2 - x1

       dy = y2-y1

       dsquared = dx**2 + dy**2

       result = math.sqrt(dsquared)

       return result

if that works correctly, you are done. Otherwise, you might want to print the value of result before the return statement.

The final version of the function doesn't display anything when it runs; it only returns a value. The prints statements we wrote are useful for debugging, but once you get the function working, you should remove them. 

 

AT
S Tombow ABT
N15
Acid Free
Transcribed Image Text:AT S Tombow ABT N15 Acid Free
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education