-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculatorUsingStreamlit.py
53 lines (52 loc) · 1.89 KB
/
calculatorUsingStreamlit.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
num1 = st.number_input("Enter the First Number")
operation = st.selectbox(
"Select Operation", ("Add", "Substract", "Multiply", "Divide", "Modulus", "Raised to the Power"))
num2 = st.number_input("Enter the Second Number")
output_type = st.radio(
"Select Output Type", ("Int", "Float"))
st.write("### Output :")
if output_type == "Float":
if operation == "Add":
result = (num1 + num2)
st.write(f"## {num1}+{num2} = {result}")
elif operation == "Substract":
result = (num1 - num2)
st.write(f"## {num1}-{num2} = {result}")
elif operation == "Multiply":
result = (num1 * num2)
st.write(f"## {num1}*{num2} = {result}")
elif operation == "Divide":
result = (num1 / num2)
st.write(f"## {num1}/{num2} = {result}")
elif operation == "Modulus":
result = (num1 % num2)
st.write(f"## {num1}%{num2} = {result}")
elif operation == "Raised to the Power":
result = (num1 ** num2)
st.write(f"## {num1}^{num2} = {result}")
else:
st.write("Choose a valid operation")
if output_type == "Int":
num1 = int(num1)
num2 = int(num2)
if operation == "Add":
result = int(num1 + num2)
st.write(f"## {num1}+{num2} = {result}")
elif operation == "Substract":
result = int(num1 - num2)
st.write(f"## {num1}-{num2} = {result}")
elif operation == "Multiply":
result = int(num1 * num2)
st.write(f"## {num1}*{num2} = {result}")
elif operation == "Divide":
result = int(num1 / num2)
st.write(f"## {num1}/{num2} = {result}")
elif operation == "Modulus":
result = int(num1 % num2)
st.write(f"## {num1}%{num2} = {result}")
elif operation == "Raised to the Power":
result = int(num1 ** num2)
st.write(f"## {num1}^{num2} = {result}")
else:
st.write("Choose a valid operation")