Given a right triangle with sides of length A and B, the length of the hypotenuse C can be calculated using the Pythagorean theorem.
right triangle
A2 + B2 = C2
Written another way, we can solve for length C by taking the square root as follows:
C = √(A2 + B2)
The program below asks the user to enter lengths for sides A and B. It should then calculate and display the length of the hypotenuse C using the Pythagorean theorem.
Use the math.pow() function to calculate A2.
Use the math.pow() function to calculate B2.
Use the math.sqrt() function to calculate the square root of A2 plus B2.
Print the result to the screen with the message "C = [result]".
You can declare any additional variables you need (if any) to implement your logic. The following examples demonstrate the expected program output.
Enter side A: 3
Enter side B: 4
C = 5.0
Enter side A: 10.5
Enter side B: 11.2
C = 15.352198539622917
Enter side A: 5
Enter side B: 12
C = 13.0
import math
A = float(input("Enter side A: "))
B = float(input("Enter side B: "))
11 answers
B_squared = math.pow(B, 2)
C = math.sqrt(A_squared + B_squared)
print(f"C = {C}")
A = float(input("Enter side A: "))
B = float(input("Enter side B: "))
B_squared = math.pow(B, 2)
C = math.sqrt(A_squared + B_squared)
print(f"C = {C}")
import math
A = float(input("Enter side A: "))
B = float(input("Enter side B: "))
A = float(input("Enter side A: "))
B = float(input("Enter side B: "))
A_squared = math.pow(A, 2)
B_squared = math.pow(B, 2)
C = math.sqrt(A_squared + B_squared)
print(f"C = {C}")
```python
import math
A = float(input("Enter side A: "))
B = float(input("Enter side B: "))
C = math.sqrt(math.pow(A, 2) + math.pow(B, 2))
print(f"C = {C}")
```
This code will correctly calculate and display the length of the hypotenuse C of a right triangle given the input lengths of sides A and B.
```python
import math
A = float(input("Enter side A: "))
B = float(input("Enter side B: "))
C = math.sqrt(2 + B**2)
print(f"C = {C}")
```
This code will calculate and display the length of the hypotenuse C of a right triangle using the Pythagorean theorem when the lengths of sides A and B are provided by the user.
import math
A = float(input("Enter side A: "))
B = float(input("Enter side B: "))
A_squared = math.pow(A, 2)
B_squared = math.pow(B, 2)
C = math.sqrt(A_squared + B_squared)
print(f"C = {C}")
```
This code now includes the use of `math.pow()` function to calculate squares for side A and side B as requested.