Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Function to calculate grade based on percentage
|
| 4 |
+
def calculate_grade(percentage):
|
| 5 |
+
if percentage >= 90:
|
| 6 |
+
return "A+"
|
| 7 |
+
elif percentage >= 80:
|
| 8 |
+
return "A"
|
| 9 |
+
elif percentage >= 70:
|
| 10 |
+
return "B"
|
| 11 |
+
elif percentage >= 60:
|
| 12 |
+
return "C"
|
| 13 |
+
elif percentage >= 50:
|
| 14 |
+
return "D"
|
| 15 |
+
else:
|
| 16 |
+
return "F"
|
| 17 |
+
|
| 18 |
+
# Main application
|
| 19 |
+
def main():
|
| 20 |
+
st.title("Student Result Application")
|
| 21 |
+
st.subheader("Enter student details and marks to calculate the result.")
|
| 22 |
+
|
| 23 |
+
# Input fields for student details
|
| 24 |
+
student_name = st.text_input("Enter the student's name:")
|
| 25 |
+
roll_number = st.text_input("Enter the roll number:")
|
| 26 |
+
num_subjects = st.number_input("Enter the number of subjects:", min_value=1, step=1)
|
| 27 |
+
|
| 28 |
+
# Marks input section
|
| 29 |
+
if num_subjects > 0:
|
| 30 |
+
marks = []
|
| 31 |
+
for i in range(num_subjects):
|
| 32 |
+
marks.append(st.number_input(f"Enter marks for subject {i + 1}:", min_value=0.0, max_value=100.0, step=0.1))
|
| 33 |
+
|
| 34 |
+
if st.button("Calculate Result"):
|
| 35 |
+
# Calculate total marks and percentage
|
| 36 |
+
total_marks = sum(marks)
|
| 37 |
+
max_marks = num_subjects * 100
|
| 38 |
+
percentage = (total_marks / max_marks) * 100
|
| 39 |
+
|
| 40 |
+
# Calculate grade
|
| 41 |
+
grade = calculate_grade(percentage)
|
| 42 |
+
|
| 43 |
+
# Display the result
|
| 44 |
+
st.success("Result Calculated Successfully!")
|
| 45 |
+
st.write("### Student Details")
|
| 46 |
+
st.write(f"**Name:** {student_name}")
|
| 47 |
+
st.write(f"**Roll Number:** {roll_number}")
|
| 48 |
+
st.write("### Result")
|
| 49 |
+
st.write(f"**Total Marks:** {total_marks}/{max_marks}")
|
| 50 |
+
st.write(f"**Percentage:** {percentage:.2f}%")
|
| 51 |
+
st.write(f"**Grade:** {grade}")
|
| 52 |
+
|
| 53 |
+
# Option to save result
|
| 54 |
+
save_result = st.checkbox("Save result as a text file")
|
| 55 |
+
if save_result:
|
| 56 |
+
result_text = (
|
| 57 |
+
f"--- Result ---\n"
|
| 58 |
+
f"Name: {student_name}\n"
|
| 59 |
+
f"Roll Number: {roll_number}\n"
|
| 60 |
+
f"Total Marks: {total_marks}/{max_marks}\n"
|
| 61 |
+
f"Percentage: {percentage:.2f}%\n"
|
| 62 |
+
f"Grade: {grade}\n"
|
| 63 |
+
)
|
| 64 |
+
with open(f"{student_name}_result.txt", "w") as file:
|
| 65 |
+
file.write(result_text)
|
| 66 |
+
st.success("Result saved successfully! Check your application directory.")
|
| 67 |
+
|
| 68 |
+
# Run the app
|
| 69 |
+
if __name__ == "__main__":
|
| 70 |
+
main()
|