Delete app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485import streamlit as st
# List of objects and related questions (example)objects_and_questions = { "Cat": [ "Is it alive?", "Is it a pet?", "Does it have fur?", "Is it a small animal?", "Does it meow?" ], "Car": [ "Is it something that moves on wheels?", "Can it be driven?", "Is it used for transportation?", "Does it have an engine?", "Is it a four-wheeled vehicle?" ], "Banana": [ "Is it a fruit?", "Is it yellow?", "Does it grow on trees?", "Is it edible?", "Is it sweet?" ]}
# Function to start the gamedef start_game(): st.title("Think of a Thing and I'll Try to Guess It!") # Initial instructions st.write("Think of something, and I will try to guess it by asking you up to 10 yes/no questions.")
# Initialize game state questions_asked = 0 possible_objects = list(objects_and_questions.keys()) # Start with all objects current_questions = {} # Dict to track questions for each object
while questions_asked < 10 and len(possible_objects) > 1: question = None for obj in possible_objects: if obj not in current_questions: current_questions[obj] = 0 # Start with the first question for this object if current_questions[obj] < len(objects_and_questions[obj]): # Get the next unanswered question for the object question = objects_and_questions[obj][current_questions[obj]] break if not question: break
# Ask the question answer = st.radio(question, ('Yes', 'No'), key=questions_asked) # Update the progress if answer == 'Yes': possible_objects = [obj for obj in possible_objects if objects_and_questions[obj][current_questions[obj]] == question] else: possible_objects = [obj for obj in possible_objects if objects_and_questions[obj][current_questions[obj]] != question] # Move to the next question for the object for obj in possible_objects: current_questions[obj] += 1 questions_asked += 1
# After 10 questions or fewer, try to guess if len(possible_objects) == 1: st.write(f"I think you were thinking of a **{possible_objects[0]}**!") elif len(possible_objects) > 1: st.write("I couldn't guess your object with certainty. Maybe you can narrow it down a bit?") else: st.write("I couldn't guess anything based on the questions asked.")
# Main function for Streamlitdef main(): st.title("Guess My Thing Game")
# Start button if st.button("Start Game"): start_game()
if __name__ == "__main__": main()app.pyDeleted-85