Presume that a ladder is put upright against a wall. Let variables length and angle store the length of the ladder and the angle that it forms with the ground as it leans against the wall. Write a Python program to compute the height reached by the ladder on the wall for the following values of length and angle: a) 16 feet and 75 degrees b) 20 feet and 0 degrees c) 24 feet and 45 degrees d) 24 feet and 80 degrees
Question
Presume that a ladder is put upright against a wall. Let variables length and angle store the length of the ladder and the angle that it forms with the ground as it leans against the wall. Write a Python program to compute the height reached by the ladder on the wall for the following values of length and angle:
a) 16 feet and 75 degrees
b) 20 feet and 0 degrees
c) 24 feet and 45 degrees
d) 24 feet and 80 degrees
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
Here is a Python program to compute the height reached by a ladder on the wall for given lengths and angles:
import math
# Function to calculate the height reached by the ladder
def height_reached(length, angle_degrees):
angle_radians = math.radians(angle_degrees) # Convert angle to radians
height = length * math.sin(angle_radians) # Calculate height using sine
return height
# Test cases
ladder_cases = [
(16, 75),
(20, 0),
(24, 45),
(24, 80)
]
for length, angle in ladder_cases:
height = height_reached(length, angle)
print(f"Length: {length} feet, Angle: {angle} degrees, Height reached: {height:.2f} feet")
Explanation of the Code:
Import the
math
module: This module provides access to mathematical functions likesin
which calculates the sine of an angle.Define a function
height_reached
:Convert the angle from degrees to radians using
math.radians
.Calculate the height using the formula $ \text{height} = \text{length} \times \sin(\text{angle in radians}) $. The sine function is used to find the vertical component of the ladder length.
Iterate through the test cases:
Compute and print the height reached by the ladder for each (length, angle) pair.
Output:
Length: 16 feet, Angle: 75 degrees, Height reached: 15.45 feet
Length: 20 feet, Angle: 0 degrees, Height reached: 0.00 feet
Length: 24 feet, Angle: 45 degrees, Height reached: 16.97 feet
Length: 24 feet, Angle: 80 degrees, Height reached: 23.64 feet
This will show the height on the wall reached by the ladder for the specified lengths and angles.
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month