Answer: Build a Streamlit page that takes basic salary, DA% and HRA% with st.number_input and shows Gross = Basic + DA + HRA with st.write.
What is Streamlit? Streamlit is an open-source Python library that turns a plain Python script into a web app. Widgets such as st.text_input and st.number_input take input, st.header shows a heading and st.write shows output. Every time an input changes, the script runs again from the top and the page updates.
Steps
- Install and import: pip install streamlit, then import streamlit as st.
- Heading with st.header(...).
- Inputs: st.text_input for the name, st.number_input for basic salary and percentages (it returns a float, so keep it as float; int() would turn 12.5% into 12%).
- Compute DA = Basic × DA% / 100, HRA = Basic × HRA% / 100, Gross = Basic + DA + HRA.
- Show results with st.write, rounded to 2 decimals.
Complete code (save as salary_app.py)
import streamlit as st
st.header("Employee Gross Salary Calculator")
name = st.text_input("Enter name of employee")
basic = st.number_input("Enter basic salary", min_value=0.0, step=500.0)
da_pct = st.number_input("DA percentage", min_value=0.0, step=0.5)
hra_pct = st.number_input("HRA percentage", min_value=0.0, step=0.5)
# no int() here, so 12.5 % DA stays 12.5 %
da = basic * da_pct / 100
hra = basic * hra_pct / 100
gross = basic + da + hra
st.write("Salary details of", name)
st.write("Dearness Allowance (DA):", round(da, 2))
st.write("House Rent Allowance (HRA):", round(hra, 2))
st.write("Gross Salary:", round(gross, 2))Run it
streamlit run salary_app.pyThe app opens in the browser at http://localhost:8501. For name Ravi Patil, basic 25000, DA 12.5 and HRA 20 the page shows:
Salary details of Ravi Patil
Dearness Allowance (DA): 3125.0
House Rent Allowance (HRA): 5000.0
Gross Salary: 33125.0(These values were checked by running the same calculation in Python 3: 25000 + 3125 + 5000 = 33125.)