Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def calculate_gpa(grades, credits):
|
4 |
+
total_points = sum(g * c for g, c in zip(grades, credits))
|
5 |
+
total_credits = sum(credits)
|
6 |
+
return round(total_points / total_credits, 2) if total_credits else 0
|
7 |
+
|
8 |
+
# Streamlit UI
|
9 |
+
st.title("GPA Calculator")
|
10 |
+
|
11 |
+
num_courses = st.number_input("Enter number of courses:", min_value=1, step=1)
|
12 |
+
|
13 |
+
grades = []
|
14 |
+
credits = []
|
15 |
+
|
16 |
+
for i in range(num_courses):
|
17 |
+
col1, col2 = st.columns(2)
|
18 |
+
with col1:
|
19 |
+
grade = st.selectbox(f"Grade for Course {i+1}", options=["A", "B", "C", "D", "F"], index=0, key=f"grade{i}")
|
20 |
+
with col2:
|
21 |
+
credit = st.number_input(f"Credit Hours for Course {i+1}", min_value=1, step=1, key=f"credit{i}")
|
22 |
+
|
23 |
+
grade_points = {"A": 4.0, "B": 3.0, "C": 2.0, "D": 1.0, "F": 0.0}
|
24 |
+
grades.append(grade_points[grade])
|
25 |
+
credits.append(credit)
|
26 |
+
|
27 |
+
if st.button("Calculate GPA"):
|
28 |
+
gpa = calculate_gpa(grades, credits)
|
29 |
+
st.success(f"Your GPA is: {gpa}")
|