mishiawan commited on
Commit
2a7f6fd
·
verified ·
1 Parent(s): 6910b60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -50
app.py CHANGED
@@ -1,75 +1,114 @@
1
  import streamlit as st
2
 
3
- # Sample data
4
- data = {
5
- 1: {"student_name": "Ali", "father_name": "Ahmed", "papers_cleared": 6, "marks": {"English": 69, "Urdu": 34, "Math": 56, "Computer": 54}},
6
- 2: {"student_name": "Sara", "father_name": "Ahad", "papers_cleared": 4, "marks": {"English": 21, "Urdu": 34, "Math": 67, "Computer": 67}},
7
- 3: {"student_name": "Sana", "father_name": "Musa", "papers_cleared": 5, "marks": {"English": 34, "Urdu": 34, "Math": 67, "Computer": 23}},
8
- 4: {"student_name": "Saba", "father_name": "Mazz", "papers_cleared": 6, "marks": {"English": 80, "Urdu": 56, "Math": 44, "Computer": 67}},
9
- 5: {"student_name": "Amir", "father_name": "Amla", "papers_cleared": 6, "marks": {"English": 76, "Urdu": 67, "Math": 43, "Computer": 80}},
10
- }
11
-
12
- # Helper function to calculate percentage and determine grade and ratio
13
  def calculate_results(marks):
14
  total_marks = sum(marks.values())
15
- percentage = (total_marks / 400) * 100 # Assuming 400 is the total possible marks (4 subjects, 100 each)
16
- if percentage >= 80:
 
 
17
  grade = "A+"
18
- ratio = "Pass"
19
  elif percentage >= 70:
20
  grade = "A"
21
- ratio = "Pass"
22
  elif percentage >= 60:
23
  grade = "B"
24
- ratio = "Pass"
25
  elif percentage >= 50:
26
  grade = "C"
27
- ratio = "Pass"
28
- elif percentage >= 40:
29
- grade = "D"
30
- ratio = "Fail"
31
  else:
32
- grade = "F"
33
- ratio = "Fail"
34
- return percentage, grade, ratio
35
 
36
- # Streamlit app
37
- st.title("Student Result Checker")
 
 
 
 
 
 
38
 
39
- # College name selection
40
- college_name = st.selectbox(
41
- "Select your college",
42
- ["Select", "College A", "College B", "College C"]
 
 
 
 
 
 
43
  )
44
 
45
- # Class selection
46
- class_number = st.selectbox(
47
- "Select your class",
48
- ["Select"] + list(range(1, 11))
49
- )
50
 
51
- # Roll number input
52
- roll_number = st.number_input("Enter your roll number", min_value=1, max_value=5, step=1)
53
 
54
- # Check and display results only when a college and class are selected
55
- if college_name != "Select" and class_number != "Select":
56
- if st.button("Check Result"):
57
- if roll_number in data:
58
- student_data = data[roll_number]
59
- marks = student_data["marks"]
60
- percentage, grade, ratio = calculate_results(marks)
61
- st.write(f"**College Name:** {college_name}")
62
- st.write(f"**Class:** {class_number}")
63
- st.write(f"**Student Name:** {student_data['student_name']}")
64
- st.write(f"**Father Name:** {student_data['father_name']}")
65
- st.write(f"**Papers Cleared:** {student_data['papers_cleared']}/6")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  st.write(f"**Marks:**")
67
  for subject, mark in marks.items():
68
  st.write(f" - {subject}: {mark}")
69
  st.write(f"**Percentage:** {percentage:.2f}%")
70
  st.write(f"**Grade:** {grade}")
71
- st.write(f"**Result:** {ratio}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  else:
73
  st.error("Invalid roll number. Please try again.")
74
- else:
75
- st.warning("Please select your college and class to proceed.")
 
1
  import streamlit as st
2
 
3
+ # Helper function to calculate percentage, grade, and pass/fail ratio
 
 
 
 
 
 
 
 
 
4
  def calculate_results(marks):
5
  total_marks = sum(marks.values())
6
+ percentage = (total_marks / 400) * 100 # Assuming 4 subjects with 100 marks each
7
+ if percentage >= 90:
8
+ grade = "A++"
9
+ elif percentage >= 80:
10
  grade = "A+"
 
11
  elif percentage >= 70:
12
  grade = "A"
 
13
  elif percentage >= 60:
14
  grade = "B"
 
15
  elif percentage >= 50:
16
  grade = "C"
 
 
 
 
17
  else:
18
+ grade = "Fail"
19
+ return percentage, grade
 
20
 
21
+ # Sample data for the student section
22
+ student_data = {
23
+ 1: {"student_name": "Ali", "father_name": "Ahmed", "papers_cleared": 6, "marks": {"English": 69, "Urdu": 34, "Math": 56, "Computer": 54}},
24
+ 2: {"student_name": "Sara", "father_name": "Ahad", "papers_cleared": 4, "marks": {"English": 21, "Urdu": 34, "Math": 67, "Computer": 67}},
25
+ 3: {"student_name": "Sana", "father_name": "Musa", "papers_cleared": 5, "marks": {"English": 34, "Urdu": 34, "Math": 67, "Computer": 23}},
26
+ 4: {"student_name": "Saba", "father_name": "Mazz", "papers_cleared": 6, "marks": {"English": 80, "Urdu": 56, "Math": 44, "Computer": 67}},
27
+ 5: {"student_name": "Amir", "father_name": "Amla", "papers_cleared": 6, "marks": {"English": 76, "Urdu": 67, "Math": 43, "Computer": 80}},
28
+ }
29
 
30
+ # Set the background color to sky blue
31
+ st.markdown(
32
+ """
33
+ <style>
34
+ .main {
35
+ background-color: #87CEEB;
36
+ }
37
+ </style>
38
+ """,
39
+ unsafe_allow_html=True,
40
  )
41
 
42
+ # Title
43
+ st.title("School Result Management System")
 
 
 
44
 
45
+ # Layout with two columns: Teacher and Student sections
46
+ left_col, right_col = st.columns(2)
47
 
48
+ # Teacher Section
49
+ with left_col:
50
+ st.header("Teacher Section (Paid)")
51
+ st.write("One-time payment: $5 for 1 year access.")
52
+ st.write("Manage student data and calculate results.")
53
+
54
+ # School name input
55
+ school_name = st.text_input("Enter your school name", placeholder="e.g., ABC High School")
56
+
57
+ # Student information inputs
58
+ student_name = st.text_input("Enter student name", placeholder="e.g., John Doe")
59
+ father_name = st.text_input("Enter father's name", placeholder="e.g., Mr. Doe")
60
+ roll_number = st.number_input("Enter roll number", min_value=1, step=1)
61
+ papers_cleared = st.number_input("Enter papers cleared (out of 6)", min_value=0, max_value=6, step=1)
62
+
63
+ # Subject marks inputs
64
+ marks = {
65
+ "English": st.number_input("Enter marks for English", min_value=0, max_value=100, step=1),
66
+ "Urdu": st.number_input("Enter marks for Urdu", min_value=0, max_value=100, step=1),
67
+ "Math": st.number_input("Enter marks for Math", min_value=0, max_value=100, step=1),
68
+ "Computer": st.number_input("Enter marks for Computer", min_value=0, max_value=100, step=1),
69
+ }
70
+
71
+ # Payment button
72
+ if st.button("Pay $5"):
73
+ st.success("Payment successful! You have 1-year access.")
74
+
75
+ # Calculate and display results
76
+ if st.button("Submit and Calculate Results"):
77
+ if all(value == 0 for value in marks.values()):
78
+ st.warning("Please enter marks for all subjects.")
79
+ else:
80
+ percentage, grade = calculate_results(marks)
81
+ st.write(f"**School Name:** {school_name}")
82
+ st.write(f"**Student Name:** {student_name}")
83
+ st.write(f"**Father Name:** {father_name}")
84
+ st.write(f"**Roll Number:** {roll_number}")
85
+ st.write(f"**Papers Cleared:** {papers_cleared}/6")
86
  st.write(f"**Marks:**")
87
  for subject, mark in marks.items():
88
  st.write(f" - {subject}: {mark}")
89
  st.write(f"**Percentage:** {percentage:.2f}%")
90
  st.write(f"**Grade:** {grade}")
91
+
92
+ # Student Section
93
+ with right_col:
94
+ st.header("Student Section")
95
+ st.write("Enter your roll number to check your result.")
96
+
97
+ # Roll number input
98
+ student_roll_number = st.number_input("Enter your roll number", min_value=1, max_value=5, step=1)
99
+
100
+ # Fetch and display student results
101
+ if st.button("Check Result"):
102
+ if student_roll_number in student_data:
103
+ student = student_data[student_roll_number]
104
+ percentage, grade = calculate_results(student["marks"])
105
+ st.write(f"**Student Name:** {student['student_name']}")
106
+ st.write(f"**Father Name:** {student['father_name']}")
107
+ st.write(f"**Papers Cleared:** {student['papers_cleared']}/6")
108
+ st.write(f"**Marks:**")
109
+ for subject, mark in student["marks"].items():
110
+ st.write(f" - {subject}: {mark}")
111
+ st.write(f"**Percentage:** {percentage:.2f}%")
112
+ st.write(f"**Grade:** {grade}")
113
  else:
114
  st.error("Invalid roll number. Please try again.")