Qasim-03 commited on
Commit
eb81aab
·
verified ·
1 Parent(s): 597263c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -33
app.py CHANGED
@@ -11,43 +11,41 @@ def main():
11
  for i in range(num_inputs):
12
  numbers.append(st.number_input(f"Enter number {i+1}", value=0.0, format="%.2f"))
13
 
14
- operation = st.selectbox("Choose an operation", ["Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Exponentiation (Base^Power)", "Floor Division"])
15
 
16
  result = numbers[0]
17
  if st.button("Calculate"):
18
  try:
19
- for index, num in enumerate(numbers[1:]):
20
- if operation == "Addition":
21
- result += num
22
- elif operation == "Subtraction":
23
- result -= num
24
- elif operation == "Multiplication":
25
- result *= num
26
- elif operation == "Division":
27
- if num != 0:
28
- result /= num
29
- else:
30
- st.error("Cannot divide by zero!")
31
- return
32
- elif operation == "Modulus":
33
- if num != 0:
34
- result %= num
35
- else:
36
- st.error("Cannot find modulus with zero!")
37
- return
38
- elif operation == "Exponentiation (Base^Power)":
39
- if index == 0:
40
- base = result
41
- power = num
42
- result = base ** power
43
- else:
44
- result **= num
45
- elif operation == "Floor Division":
46
- if num != 0:
47
- result //= num
48
- else:
49
- st.error("Cannot perform floor division by zero!")
50
- return
51
 
52
  st.success(f"Result: {result}")
53
  except Exception as e:
 
11
  for i in range(num_inputs):
12
  numbers.append(st.number_input(f"Enter number {i+1}", value=0.0, format="%.2f"))
13
 
14
+ operation = st.selectbox("Choose an operation", ["Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Exponentiation", "Floor Division"])
15
 
16
  result = numbers[0]
17
  if st.button("Calculate"):
18
  try:
19
+ if operation == "Exponentiation":
20
+ base = st.number_input("Enter the base", value=1.0, format="%.2f")
21
+ exponent = st.number_input("Enter the exponent", value=1.0, format="%.2f")
22
+ result = base ** exponent
23
+ else:
24
+ for index, num in enumerate(numbers[1:]):
25
+ if operation == "Addition":
26
+ result += num
27
+ elif operation == "Subtraction":
28
+ result -= num
29
+ elif operation == "Multiplication":
30
+ result *= num
31
+ elif operation == "Division":
32
+ if num != 0:
33
+ result /= num
34
+ else:
35
+ st.error("Cannot divide by zero!")
36
+ return
37
+ elif operation == "Modulus":
38
+ if num != 0:
39
+ result %= num
40
+ else:
41
+ st.error("Cannot find modulus with zero!")
42
+ return
43
+ elif operation == "Floor Division":
44
+ if num != 0:
45
+ result //= num
46
+ else:
47
+ st.error("Cannot perform floor division by zero!")
48
+ return
 
 
49
 
50
  st.success(f"Result: {result}")
51
  except Exception as e: