Jeopardy Business Quiz by KR!
To upload files, please first save the app
import streamlit as st
import pandas as pd
import random
# Set page title and configuration
st.set_page_config(page_title="Jeopardy Business Quiz", layout="wide")
st.title("🎯 Business Jeopardy Quiz")
# Initialize session state
if 'score' not in st.session_state:
st.session_state.score = 0
if 'questions_asked' not in st.session_state:
st.session_state.questions_asked = set()
if 'current_question' not in st.session_state:
st.session_state.current_question = None
# Business-related questions and answers
questions = [
{
"category": "Companies",
"value": 200,
"question": "This tech giant was founded in a garage in Palo Alto by Bill Hewlett and Dave Packard in 1939",
"answer": "What is HP (Hewlett-Packard)?",
},
{
"category": "Companies",
"value": 400,
"question": "This company's first product was a wood-picture frame, and its founder Sam Walton opened his first store in 1962",
"answer": "What is Walmart?",
},
{
"category": "CEOs",
"value": 200,
"question": "He dropped out of Harvard to found Microsoft",
"answer": "Who is Bill Gates?",
},
{
"category": "CEOs",
"value": 400,
"question": "This CEO of Tesla and SpaceX became the world's richest person in 2021",
"answer": "Who is Elon Musk?",
},
{
"category": "Business Terms",
"value": 200,
"question": "This 'B' word refers to the amount of money a company owes compared to what it owns",
"answer": "What is Balance Sheet?",
},
{
"category": "Business Terms",
"value": 400,
"question": "This is the term for buying a company using mostly borrowed money",
"answer": "What is Leveraged Buyout (LBO)?",
},
{
"category": "Stock Market",
"value": 200,
"question": "This animal represents a market where stock prices are rising",
"answer": "What is a Bull Market?",
},
{
"category": "Stock Market",
"value": 400,
"question": "This index of 30 large companies is often called 'The Dow'",
"answer": "What is the Dow Jones Industrial Average?",
},
]
# Sidebar with score and instructions
with st.sidebar:
st.header("Game Stats")
st.metric("Current Score", st.session_state.score)
st.markdown("---")
st.markdown("""
### How to Play
1. Click 'New Question' to get a question
2. Type your answer in the format:
- "What is..." for things
- "Who is..." for people
3. Click 'Submit Answer' to check if you're correct
""")
if st.button("Reset Game"):
st.session_state.score = 0
st.session_state.questions_asked = set()
st.session_state.current_question = None
st.rerun()
# Main game area
col1, col2 = st.columns([2, 1])
with col1:
if st.button("New Question"):
available_questions = [q for i, q in enumerate(questions) if i not in st.session_state.questions_asked]
if available_questions:
st.session_state.current_question = random.choice(available_questions)
st.session_state.questions_asked.add(questions.index(st.session_state.current_question))
else:
st.success("🎉 Congratulations! You've completed all questions! Reset the game to play again.")
st.session_state.current_question = None
if st.session_state.current_question:
st.markdown(f"### Category: {st.session_state.current_question['category']} (${st.session_state.current_question['value']})")
st.markdown(f"**{st.session_state.current_question['question']}**")
user_answer = st.text_input("Your Answer:")
if st.button("Submit Answer"):
correct_answer = st.session_state.current_question['answer'].lower()
if user_answer.lower() in correct_answer.lower():
st.success("Correct! 🎉")
st.session_state.score += st.session_state.current_question['value']
else:
st.error(f"Sorry, the correct answer was: {st.session_state.current_question['answer']}")
st.session_state.score -= st.session_state.current_question['value']
st.session_state.current_question = None
st.rerun()
with col2:
st.markdown("### Categories Available")
categories = list(set(q['category'] for q in questions))
for category in categories:
st.markdown(f"- {category}")
# Footer
st.markdown("---")
st.markdown("Created by KR | A Business Quiz in Jeopardy Style 🎮")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?