Create a streamlit application mimicking the classic "simon says" game, but instead of colours there are syllables on the game buttons and there are ten buttons
To upload files, please first save the app
import streamlit as st
import random
st.title("Syllable Simon Says")
# Define syllables
syllables = ["ba", "da", "ka", "la", "ma", "na", "ta", "pa", "sa", "ra"]
# Initialize session state for game sequence and user input
if 'sequence' not in st.session_state:
st.session_state.sequence = []
if 'user_input' not in st.session_state:
st.session_state.user_input = []
# Function to generate a new syllable
def generate_syllable():
return random.choice(syllables)
# Function to start a new game round
def new_round():
new_syllable = generate_syllable()
st.session_state.sequence.append(new_syllable)
st.session_state.user_input = []
st.write(f"New syllable to remember: {new_syllable}")
# Display buttons and handle input
for syl in syllables:
if st.button(syl):
st.session_state.user_input.append(syl)
st.write(f"You pressed: {syl}")
# Check user input
if st.button("Check Sequence"):
if st.session_state.user_input == st.session_state.sequence:
st.success("Correct sequence!")
new_round()
else:
st.error("Wrong sequence! Try again.")
# Start the first round
if st.button("Start Game"):
new_round()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?