Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Sample questions (Replace or expand with full 50 questions)
|
| 5 |
+
questions = [
|
| 6 |
+
{"subject": "Math", "question": "What is 12 × 3?", "options": ["36", "45", "24", "18"], "answer": "36"},
|
| 7 |
+
{"subject": "Math", "question": "What is the half of 100?", "options": ["25", "50", "10", "100"], "answer": "50"},
|
| 8 |
+
{"subject": "English", "question": "Choose the noun: The dog barked loudly.", "options": ["dog", "barked", "loudly", "the"], "answer": "dog"},
|
| 9 |
+
{"subject": "English", "question": "What is the opposite of 'happy'?", "options": ["glad", "sad", "joy", "smile"], "answer": "sad"},
|
| 10 |
+
{"subject": "Science", "question": "What do plants need for photosynthesis?", "options": ["Sunlight", "Milk", "Sugar", "Salt"], "answer": "Sunlight"},
|
| 11 |
+
{"subject": "Science", "question": "Which planet is called the Red Planet?", "options": ["Earth", "Mars", "Venus", "Jupiter"], "answer": "Mars"},
|
| 12 |
+
# Add more questions here to reach 50
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
# Shuffle and limit to 50
|
| 16 |
+
random.shuffle(questions)
|
| 17 |
+
questions = questions[:50]
|
| 18 |
+
|
| 19 |
+
st.title("Grade 5 Online Test")
|
| 20 |
+
st.markdown("Please answer the following 50 questions:")
|
| 21 |
+
|
| 22 |
+
score = 0
|
| 23 |
+
user_answers = []
|
| 24 |
+
|
| 25 |
+
with st.form("test_form"):
|
| 26 |
+
for i, q in enumerate(questions):
|
| 27 |
+
user_input = st.radio(f"{i+1}. ({q['subject']}) {q['question']}", q["options"], key=i)
|
| 28 |
+
user_answers.append({"question": q["question"], "correct": q["answer"], "user": user_input})
|
| 29 |
+
submitted = st.form_submit_button("Submit")
|
| 30 |
+
|
| 31 |
+
if submitted:
|
| 32 |
+
score = sum(1 for ans in user_answers if ans["user"] == ans["correct"])
|
| 33 |
+
st.success(f"Your score is {score} out of {len(questions)}.")
|
| 34 |
+
st.progress(score / len(questions))
|