Compute hypotenuse in python assignment expert

Compute Hypotenuse

Write a program to find the hypotenuse H of a right-angled triangle of sides A and B.

Note: Pythagoras theorem states that, for a right-angled triangle. Hypotenuse2 = A2 + B2Input

The first line is an integer, A. The second line is an integer, B.

Output

The output should be an integer.

In the given example, the first side

A = 3, and the second side B = 4. To calculate the hypotenuse we use Pythagoras theorem.

According to Pythagoras theorem, hypotenuse2 = 32 + 42

Therefore, the hypotenuse value is

5. So, the output should be 5.

Sample Input 1

3

4

Sample Output 1

5

Sample Input 2

12

5

Sample Output 2

13

Compute Hypotenuse

Write a program to find the hypotenuse 

H of a right-angled triangle of sides A and B.

Note: Pythagoras theorem states that, for a right-angled triangle. Hypotenuse2 = A2 + B2

Input

The first line is an integer, 

A. The second line is an integer, B.

Output

The output should be an integer.

Explanation

In the given example, the first side 

A = 3, and the second side B = 4. To calculate the hypotenuse we use Pythagoras theorem.

According to Pythagoras theorem, hypotenuse2 = 32 + 42

Therefore, the hypotenuse value is 

5. So, the output should be 5.

Sample Input 1
3
4
Sample Output 1
5
Sample Input 2
12
5
Sample Output 2
13

Last update on August 19 2022 21:51:49 (UTC/GMT +8 hours)

Python Basic: Exercise-60 with Solution

Write a Python program to calculate the hypotenuse of a right angled triangle.

From Wikipedia,
A right triangle or right-angled triangle, or more formally an orthogonal triangle, is a triangle in which one angle is a right angle. The relation between the sides and angles of a right triangle is the basis for trigonometry. The side opposite the right angle is called the hypotenuse. If the lengths of all three sides of a right triangle are integers, the triangle is said to be a Pythagorean triangle and its side lengths are collectively known as a Pythagorean triple.

Pictorial Presentation:

Compute hypotenuse in python assignment expert

Sample Solution-1:

Python Code :

from math import sqrt
print("Input lengths of shorter triangle sides:")
a = float(input("a: "))
b = float(input("b: "))
c = sqrt(a**2 + b**2)
print("The length of the hypotenuse is:", c )

Sample Output:

Input lengths of shorter triangle sides:
a:  3
b:  4
The length of the hypotenuse is: 5.0

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Sample Solution-2:

Python Code:

def test(x, y):
   h = (x**2 + y**2)**0.5
   return h
print(test(3,4))
print(test(3.5,4.4))

Sample Output:

5.0
5.622277118748239

Flowchart:

Compute hypotenuse in python assignment expert

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to convert height (in feet and inches) to centimeters.
Next: Write a Python program to convert the distance (in feet) to inches, yards, and miles.

Python: Tips of the Day

Optional Arguments:

We can pass in optional arguments by providing a default value to an argument:

def my_new_function(my_value='hello'):
  print(my_value)#Calling
my_new_function() => prints hello
my_new_function('test') => prints test

(Solved): Can I get help with this assignment in Python2.15 Lab: Hypotenuse In this lab, you will write a prog ...



Can I get help with this assignment in Python

Compute hypotenuse in python assignment expert

2.15 Lab: Hypotenuse In this lab, you will write a program that computes the length of the hypotenuse of a right triangle, using the Pythagorean Theorem: Here is the output of a program run Computing the hypotenuse of a right triangle: Enter side A: 3 Enter side B: 4 The hypotenuse of a right triangle with sides 3.0 and 4.0 is 5.0 And here is another Computing the hypotenuse of a right triangle: Enter side A: 1.0 Enter side B 0.5 right triangle with sides 1.0 and o.5 is 1.118033988749895 The hypotenuse of a LAB 2.15.1: Lab: Hypotenuse 0/10 ACTIVITY Submission Instructions Upload your files below by dragging and dropping into the area or choosing a file on your hard drive. Drag file here hypotenuse.py or Choose on hard drive. Submit for grading Show transcribed image text 2.15 Lab: Hypotenuse In this lab, you will write a program that computes the length of the hypotenuse of a right triangle, using the Pythagorean Theorem: Here is the output of a program run Computing the hypotenuse of a right triangle: Enter side A: 3 Enter side B: 4 The hypotenuse of a right triangle with sides 3.0 and 4.0 is 5.0 And here is another Computing the hypotenuse of a right triangle: Enter side A: 1.0 Enter side B 0.5 right triangle with sides 1.0 and o.5 is 1.118033988749895 The hypotenuse of a LAB 2.15.1: Lab: Hypotenuse 0/10 ACTIVITY Submission Instructions Upload your files below by dragging and dropping into the area or choosing a file on your hard drive. Drag file here hypotenuse.py or Choose on hard drive. Submit for grading

Get Expert Solution


Answer to 2.15 Lab: Hypotenuse In this lab, you will write a program that computes the length of the hypotenuse of a right triangl...

How do you find the hypotenuse in Python?

Here is how it looks in the code:.
import math..
a = float(input("Give side a: ")).
b = float(input("Give side b: ")).
c = math. sqrt(a ** 2 + b ** 2).
print(f"The length of the hypotenuse c is {c}").

How do I find the hypotenuse?

The hypotenuse is termed as the longest side of a right-angled triangle. To find the longest side we use the hypotenuse formula that can be easily driven from the Pythagoras theorem, (Hypotenuse)2 = (Base)2 + (Altitude)2. Hypotenuse formula = √((base)2 + (height)2) (or) c = √(a2 + b2).

How do you find the right triangle in Python?

Python: Check whether three given lengths of three sides form a right triangle.
Input: ... .
Pictorial Presentation:.
Sample Solution:.
Python Code: print("Input three integers(sides of a triangle)") int_num = list(map(int,input().split())) x,y,z = sorted(int_num) if x**2+y**2==z**2: print('Yes') else: print('No') ... .
Flowchart:.