File size: 1,025 Bytes
e6525c8
 
 
 
 
 
 
 
 
 
 
ae7c768
 
e6525c8
 
 
 
e13c355
e6525c8
 
 
 
 
 
 
e0fe2ed
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import streamlit as st

def calculate_c(a, b):
  """Calculates the value of c based on the Pythagorean theorem."""
  return (a**2 + b**2)**0.5  # Use square root to find c

# Create a title and explanation
st.title("Pythagorean Theorem Simulator")
st.write("Enter the values of a and b to find the hypotenuse (c) using the formula: a² + b² = c²")

# Create input fields for a and b
a = st.number_input("Enter value of a:", min_value=0)
b = st.number_input("Enter value of b:", min_value=0)

# Calculate c using the function
try:
  c = calculate_c(a, b)
  st.write("The value of c is:", c,font="large")
except ValueError:
  st.error("Please enter non-negative values for a and b.")

# Display the formula for reference
st.write("Formula: a² + b² = c²")

# Add a button for recalculating and information about right triangles
st.button("Recalculate")  # Button to trigger the calculation again
st.markdown("**Note:** This application only works for right triangles. In a right triangle, one angle is exactly 90 degrees.")