Amaanali01 commited on
Commit
8ae4718
·
verified ·
1 Parent(s): 9910b76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
app.py CHANGED
@@ -4,36 +4,42 @@ st.set_page_config(page_title="Three-Field Calculator", layout="centered")
4
 
5
  st.title("🧮 Three-Field Calculator")
6
 
 
 
7
  # Input fields
8
- num1 = st.number_input("Enter first number", value=0.0, step=0.1)
9
- num2 = st.number_input("Enter second number", value=0.0, step=0.1)
10
- num3 = st.number_input("Enter third number", value=0.0, step=0.1)
11
 
12
  # Operation selection
13
  operation = st.selectbox(
14
  "Select operation",
15
- ["Addition", "Subtraction", "Multiplication", "Division"]
16
  )
17
 
18
- # Perform calculation
 
 
19
  result = None
20
 
21
- if operation == "Addition":
22
- result = num1 + num2 + num3
 
23
 
24
- elif operation == "Subtraction":
25
- result = num1 - num2 - num3
26
 
27
- elif operation == "Multiplication":
28
- result = num1 * num2 * num3
 
 
29
 
30
- elif operation == "Division":
31
- if num2 != 0 and num3 != 0:
32
- result = num1 / num2 / num3
33
- else:
34
- st.error("Error! Division by zero.")
35
- result = None
36
 
37
- # Display result
38
- if result is not None:
39
- st.success(f"Result: {result}")
 
4
 
5
  st.title("🧮 Three-Field Calculator")
6
 
7
+ st.write("Enter three numbers and choose an operation.")
8
+
9
  # Input fields
10
+ num1 = st.number_input("Enter first number", value=0.0, step=1.0)
11
+ num2 = st.number_input("Enter second number", value=0.0, step=1.0)
12
+ num3 = st.number_input("Enter third number", value=0.0, step=1.0)
13
 
14
  # Operation selection
15
  operation = st.selectbox(
16
  "Select operation",
17
+ ("Addition", "Subtraction", "Multiplication", "Division")
18
  )
19
 
20
+ # Calculate button
21
+ calculate = st.button("Calculate")
22
+
23
  result = None
24
 
25
+ if calculate:
26
+ if operation == "Addition":
27
+ result = num1 + num2 + num3
28
 
29
+ elif operation == "Subtraction":
30
+ result = num1 - num2 - num3
31
 
32
+ elif operation == "Multiplication":
33
+ result = num1 * num2 * num3
34
+ if num2 == 0 or num3 == 0:
35
+ st.info("Multiplying by zero results in zero.")
36
 
37
+ elif operation == "Division":
38
+ if num2 == 0 or num3 == 0:
39
+ st.error("Cannot divide by zero. Please enter non-zero values for second and third numbers.")
40
+ else:
41
+ result = num1 / num2 / num3
 
42
 
43
+ # Display result
44
+ if result is not None:
45
+ st.success(f"Result: {result}")