Spaces:
Sleeping
Sleeping
import streamlit as st | |
import random | |
# Sample questions (Replace or expand with full 50 questions) | |
questions = [ | |
{"subject": "Math", "question": "What is 12 × 3?", "options": ["36", "45", "24", "18"], "answer": "36"}, | |
{"subject": "Math", "question": "What is the half of 100?", "options": ["25", "50", "10", "100"], "answer": "50"}, | |
{"subject": "English", "question": "Choose the noun: The dog barked loudly.", "options": ["dog", "barked", "loudly", "the"], "answer": "dog"}, | |
{"subject": "English", "question": "What is the opposite of 'happy'?", "options": ["glad", "sad", "joy", "smile"], "answer": "sad"}, | |
{"subject": "Science", "question": "What do plants need for photosynthesis?", "options": ["Sunlight", "Milk", "Sugar", "Salt"], "answer": "Sunlight"}, | |
{"subject": "Science", "question": "Which planet is called the Red Planet?", "options": ["Earth", "Mars", "Venus", "Jupiter"], "answer": "Mars"}, | |
# Add more questions here to reach 50 | |
] | |
# Shuffle and limit to 50 | |
random.shuffle(questions) | |
questions = questions[:50] | |
st.title("Grade 5 Online Test") | |
st.markdown("Please answer the following 50 questions:") | |
score = 0 | |
user_answers = [] | |
with st.form("test_form"): | |
for i, q in enumerate(questions): | |
user_input = st.radio(f"{i+1}. ({q['subject']}) {q['question']}", q["options"], key=i) | |
user_answers.append({"question": q["question"], "correct": q["answer"], "user": user_input}) | |
submitted = st.form_submit_button("Submit") | |
if submitted: | |
score = sum(1 for ans in user_answers if ans["user"] == ans["correct"]) | |
st.success(f"Your score is {score} out of {len(questions)}.") | |
st.progress(score / len(questions)) | |