| import streamlit as st |
| import random |
| import time |
|
|
| |
| st.sidebar.title("๐ฎ Mini Game Arcade") |
| game = st.sidebar.selectbox("Choose a Game", [ |
| "Rock Paper Scissors", "Guess the Number", "Word Scramble", "Emoji Quiz", |
| "Dice Roller", "Coin Toss", "Math Quiz", "Hangman", "Typing Speed Test", |
| "Color Guess", "Score Tracker" |
| ]) |
|
|
| |
| if game == "Rock Paper Scissors": |
| st.title("๐ชจ๐โ๏ธ Rock Paper Scissors") |
| user_choice = st.selectbox("Choose your move", ["Rock", "Paper", "Scissors"]) |
| if st.button("Play"): |
| comp_choice = random.choice(["Rock", "Paper", "Scissors"]) |
| st.write(f"Computer chose: {comp_choice}") |
| if user_choice == comp_choice: |
| st.success("It's a Tie!") |
| elif (user_choice == "Rock" and comp_choice == "Scissors") or \ |
| (user_choice == "Paper" and comp_choice == "Rock") or \ |
| (user_choice == "Scissors" and comp_choice == "Paper"): |
| st.success("You Win!") |
| else: |
| st.error("You Lose!") |
|
|
| |
| elif game == "Guess the Number": |
| st.title("๐ข Guess the Number (1-100)") |
| secret = random.randint(1, 100) |
| guess = st.number_input("Enter your guess", 1, 100, step=1) |
| if st.button("Check"): |
| if guess == secret: |
| st.success("๐ Correct!") |
| elif guess < secret: |
| st.info("Too low!") |
| else: |
| st.info("Too high!") |
|
|
| |
| elif game == "Word Scramble": |
| st.title("๐ Word Scramble") |
| words = ["streamlit", "arcade", "python", "gamer", "developer"] |
| word = random.choice(words) |
| scrambled = ''.join(random.sample(word, len(word))) |
| st.write(f"Scrambled Word: **{scrambled}**") |
| answer = st.text_input("Your Guess") |
| if st.button("Submit"): |
| if answer.lower() == word: |
| st.success("Correct!") |
| else: |
| st.error(f"Wrong! The word was {word}") |
|
|
| |
| elif game == "Emoji Quiz": |
| st.title("๐ Emoji Quiz") |
| quiz = {"๐ฌ๐": "Finding Nemo", "๐ฆ๐": "The Lion King", "๐ป๐": "Ghostbusters"} |
| emoji, answer = random.choice(list(quiz.items())) |
| st.write(f"Guess the Movie: {emoji}") |
| user = st.text_input("Your Guess") |
| if st.button("Check Answer"): |
| if user.lower() == answer.lower(): |
| st.success("Correct!") |
| else: |
| st.error(f"Nope! It was {answer}") |
|
|
| |
| elif game == "Dice Roller": |
| st.title("๐ฒ Dice Roller") |
| if st.button("Roll Dice"): |
| dice = random.randint(1, 6) |
| st.write(f"You rolled: **{dice}**") |
|
|
| |
| elif game == "Coin Toss": |
| st.title("๐ช Coin Toss") |
| if st.button("Toss Coin"): |
| result = random.choice(["Heads", "Tails"]) |
| st.write(f"It's: **{result}**") |
|
|
| |
| elif game == "Math Quiz": |
| st.title("โ Math Quiz") |
| a, b = random.randint(1, 10), random.randint(1, 10) |
| user_ans = st.number_input(f"What is {a} + {b}?", 0, 100) |
| if st.button("Submit Answer"): |
| if user_ans == a + b: |
| st.success("Correct!") |
| else: |
| st.error(f"Wrong! Answer is {a + b}") |
|
|
| |
| elif game == "Hangman": |
| st.title("๐จโ๐ค Hangman Lite") |
| word = random.choice(["apple", "banana", "grape", "mango"]) |
| hint = word[0] + "_"*(len(word)-2) + word[-1] |
| st.write(f"Hint: {hint}") |
| guess = st.text_input("Guess the word") |
| if st.button("Guess"): |
| if guess.lower() == word: |
| st.success("Correct!") |
| else: |
| st.error(f"Wrong! The word was {word}") |
|
|
| |
| elif game == "Typing Speed Test": |
| st.title("โจ๏ธ Typing Speed Test") |
| sentence = "Streamlit makes Python apps easy!" |
| st.write("Type this: ", sentence) |
| user_input = st.text_input("Start typing here") |
| if st.button("Test Speed"): |
| if user_input == sentence: |
| st.success("Perfect Match!") |
| else: |
| st.warning("Not matching. Try again!") |
|
|
| |
| elif game == "Color Guess": |
| st.title("๐จ Color Guess") |
| colors = ["Red", "Blue", "Green", "Yellow"] |
| selected = random.choice(colors) |
| guess = st.selectbox("Which color am I thinking?", colors) |
| if st.button("Guess"): |
| if guess == selected: |
| st.success("You're right!") |
| else: |
| st.error(f"Nope! It was {selected}") |
|
|
| |
| elif game == "Score Tracker": |
| st.title("๐ Score Tracker") |
| score = st.number_input("Your score:", 0, 100) |
| if score >= 80: |
| st.success("Great job! ๐ฅ") |
| elif score >= 50: |
| st.info("Keep going! ๐ฅ") |
| else: |
| st.warning("Needs improvement ๐ฅ") |
|
|