Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
# Predefined weightages from bottom to top
|
| 5 |
+
weightages = [5, 5, 10, 15, 15, 50]
|
| 6 |
+
quiz_labels = ["Quiz 1", "Quiz 2", "Quiz 3", "Quiz 4", "Quiz 5", "Grand Quiz"]
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="Quiz Marks Calculator", layout="centered")
|
| 9 |
+
|
| 10 |
+
st.title("🎯 Hacking Page – Quiz Marks Weighted Percentage Calculator")
|
| 11 |
+
st.markdown("Enter your marks below for each quiz. The final result will be calculated based on predefined weightages.")
|
| 12 |
+
|
| 13 |
+
marks_obtained = []
|
| 14 |
+
total_marks = []
|
| 15 |
+
|
| 16 |
+
# Input section
|
| 17 |
+
for i in range(6):
|
| 18 |
+
col1, col2 = st.columns(2)
|
| 19 |
+
with col1:
|
| 20 |
+
obtained = st.number_input(f"{quiz_labels[i]} - Marks Obtained", min_value=0.0, step=1.0, key=f"obtained_{i}")
|
| 21 |
+
with col2:
|
| 22 |
+
total = st.number_input(f"{quiz_labels[i]} - Total Marks", min_value=1.0, step=1.0, key=f"total_{i}")
|
| 23 |
+
marks_obtained.append(obtained)
|
| 24 |
+
total_marks.append(total)
|
| 25 |
+
|
| 26 |
+
if st.button("Calculate Percentage"):
|
| 27 |
+
data = []
|
| 28 |
+
total_weighted_percentage = 0
|
| 29 |
+
|
| 30 |
+
for i in range(6):
|
| 31 |
+
percentage = (marks_obtained[i] / total_marks[i]) * 100 if total_marks[i] != 0 else 0
|
| 32 |
+
weighted = percentage * (weightages[i] / 100)
|
| 33 |
+
total_weighted_percentage += weighted
|
| 34 |
+
data.append({
|
| 35 |
+
"Quiz": quiz_labels[i],
|
| 36 |
+
"Marks Obtained": marks_obtained[i],
|
| 37 |
+
"Total Marks": total_marks[i],
|
| 38 |
+
"Weightage (%)": weightages[i],
|
| 39 |
+
"Section %": round(percentage, 2),
|
| 40 |
+
"Contribution (%)": round(weighted, 2)
|
| 41 |
+
})
|
| 42 |
+
|
| 43 |
+
df = pd.DataFrame(data)
|
| 44 |
+
df.set_index("Quiz", inplace=True)
|
| 45 |
+
|
| 46 |
+
st.markdown("### 📊 Results Table")
|
| 47 |
+
st.dataframe(df)
|
| 48 |
+
|
| 49 |
+
st.success(f"✅ Final Weighted Percentage: **{total_weighted_percentage:.2f}%**")
|