import random import requests import streamlit as st from streamlit_lottie import st_lottie class QuoteQuizGame: def __init__(self): self.questions = [ { "question": "Who said: 'The unexamined life is not worth living'?", "choices": ["Plato", "Socrates", "Aristotle"], "correct_answer": "Socrates" }, { "question": "Which philosopher wrote: 'God is dead. God remains dead. And we have killed him.'?", "choices": ["Jean-Paul Sartre", "Friedrich Nietzsche", "Albert Camus"], "correct_answer": "Friedrich Nietzsche" }, { "question": "Who is credited with the quote: 'I think, therefore I am' (originally in Latin: 'Cogito, ergo sum')?", "choices": ["René Descartes", "Immanuel Kant", "John Locke"], "correct_answer": "René Descartes" }, { "question": "Which ancient Chinese philosopher said: 'The journey of a thousand miles begins with a single step'?", "choices": ["Confucius", "Sun Tzu", "Lao Tzu"], "correct_answer": "Lao Tzu" }, { "question": "Who wrote: 'He who has a why to live can bear almost any how'?", "choices": ["Viktor Frankl", "Friedrich Nietzsche", "Carl Jung"], "correct_answer": "Friedrich Nietzsche" }, { "question": "Which existentialist philosopher said: 'Man is condemned to be free'?", "choices": ["Albert Camus", "Simone de Beauvoir", "Jean-Paul Sartre"], "correct_answer": "Jean-Paul Sartre" }, { "question": "Who is known for the quote: 'The owl of Minerva spreads its wings only with the falling of the dusk'?", "choices": ["Georg Wilhelm Friedrich Hegel", "Arthur Schopenhauer", "Søren Kierkegaard"], "correct_answer": "Georg Wilhelm Friedrich Hegel" }, { "question": "Which philosopher wrote: 'The life of man [is] solitary, poor, nasty, brutish, and short'?", "choices": ["John Locke", "Thomas Hobbes", "Jean-Jacques Rousseau"], "correct_answer": "Thomas Hobbes" }, { "question": "Who said: 'He who fights with monsters should look to it that he himself does not become a monster'?", "choices": ["Carl Jung", "Friedrich Nietzsche", "Fyodor Dostoevsky"], "correct_answer": "Friedrich Nietzsche" }, { "question": "Which philosopher wrote: 'The function of prayer is not to influence God, but rather to change the nature of the one who prays'?", "choices": ["Søren Kierkegaard", "Blaise Pascal", "Martin Buber"], "correct_answer": "Søren Kierkegaard" } ] random.shuffle(self.questions) self.score = 0 self.current_question = 0 def get_current_question(self): return self.questions[self.current_question] def check_answer(self, answer): question = self.questions[self.current_question] if question["choices"][answer - 1] == question["correct_answer"]: self.score += 1 return True return False def next_question(self): self.current_question += 1 return self.current_question < len(self.questions) def load_lottie_url(url: str): r = requests.get(url) if r.status_code != 200: return None return r.json() def show_animation(name, url): anim = load_lottie_url(url) st_lottie(anim, key=name) def main(): st.set_page_config(page_title="Quote Quiz Game with Animations", layout="wide") st.title("Quote Quiz Game with Animations") if 'quiz_game' not in st.session_state: st.session_state.quiz_game = QuoteQuizGame() st.session_state.game_over = False quiz = st.session_state.quiz_game # Quiz Game Section st.header("PhD-level Quote Quiz Game") if not st.session_state.game_over: question = quiz.get_current_question() st.write(f"Question {quiz.current_question + 1}:") st.write(question["question"]) answer = st.radio("Choose your answer:", question["choices"], key=f"question_{quiz.current_question}") if st.button("Submit Answer"): correct = quiz.check_answer(question["choices"].index(answer) + 1) if correct: st.success("Correct!") else: st.error(f"Incorrect. The correct answer was: {question['correct_answer']}") if not quiz.next_question(): st.session_state.game_over = True if st.session_state.game_over: st.write(f"Game over! Your final score is: {quiz.score} out of {len(quiz.questions)}.") if quiz.score == len(quiz.questions): st.write("Perfect score! You're a true philosophy expert!") elif quiz.score >= len(quiz.questions) * 0.8: st.write("Excellent job! You have a deep understanding of philosophical quotes.") elif quiz.score >= len(quiz.questions) * 0.6: st.write("Good effort! You have a solid grasp of famous quotes.") elif quiz.score >= len(quiz.questions) * 0.4: st.write("Not bad! There's room for improvement in your philosophical knowledge.") else: st.write("Keep studying! The world of philosophy has much to offer.") if st.button("Play Again"): st.session_state.quiz_game = QuoteQuizGame() st.session_state.game_over = False st.experimental_rerun() # Animation Section st.header("Animations") st.markdown('# Animations: https://lottiefiles.com/recent') st.markdown("# Animate with JSON, SVG, Adobe XD, Figma, and deploy to web, mobile as tiny animation files ") col1, col2, col3 = st.columns(3) with col1: show_animation("Badge1", "https://assets5.lottiefiles.com/packages/lf20_wtohqzml.json") show_animation("Badge2", "https://assets5.lottiefiles.com/packages/lf20_i4zw2ddg.json") show_animation("Badge3", "https://assets5.lottiefiles.com/private_files/lf30_jfhmdmk5.json") show_animation("Graph", "https://assets6.lottiefiles.com/packages/lf20_4gqhiayj.json") with col2: show_animation("PhoneBot", "https://assets9.lottiefiles.com/packages/lf20_zrqthn6o.json") show_animation("SupportBot", "https://assets5.lottiefiles.com/private_files/lf30_cmd8kh2q.json") show_animation("ChatBot", "https://assets8.lottiefiles.com/packages/lf20_j1oeaifz.json") show_animation("IntelligentMachine", "https://assets8.lottiefiles.com/packages/lf20_edouagsj.json") with col3: show_animation("GearAI", "https://assets10.lottiefiles.com/packages/lf20_3jkp7dqt.json") show_animation("ContextGraph", "https://assets10.lottiefiles.com/private_files/lf30_vwC61X.json") show_animation("Yggdrasil", "https://assets4.lottiefiles.com/packages/lf20_8q1bhU.json") show_animation("Studying", "https://assets9.lottiefiles.com/packages/lf20_6ft9bypa.json") if __name__ == "__main__": main()