Delete app.py
Browse files
app.py
DELETED
|
@@ -1,85 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
|
| 3 |
-
# List of objects and related questions (example)
|
| 4 |
-
objects_and_questions = {
|
| 5 |
-
"Cat": [
|
| 6 |
-
"Is it alive?",
|
| 7 |
-
"Is it a pet?",
|
| 8 |
-
"Does it have fur?",
|
| 9 |
-
"Is it a small animal?",
|
| 10 |
-
"Does it meow?"
|
| 11 |
-
],
|
| 12 |
-
"Car": [
|
| 13 |
-
"Is it something that moves on wheels?",
|
| 14 |
-
"Can it be driven?",
|
| 15 |
-
"Is it used for transportation?",
|
| 16 |
-
"Does it have an engine?",
|
| 17 |
-
"Is it a four-wheeled vehicle?"
|
| 18 |
-
],
|
| 19 |
-
"Banana": [
|
| 20 |
-
"Is it a fruit?",
|
| 21 |
-
"Is it yellow?",
|
| 22 |
-
"Does it grow on trees?",
|
| 23 |
-
"Is it edible?",
|
| 24 |
-
"Is it sweet?"
|
| 25 |
-
]
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
# Function to start the game
|
| 29 |
-
def start_game():
|
| 30 |
-
st.title("Think of a Thing and I'll Try to Guess It!")
|
| 31 |
-
|
| 32 |
-
# Initial instructions
|
| 33 |
-
st.write("Think of something, and I will try to guess it by asking you up to 10 yes/no questions.")
|
| 34 |
-
|
| 35 |
-
# Initialize game state
|
| 36 |
-
questions_asked = 0
|
| 37 |
-
possible_objects = list(objects_and_questions.keys()) # Start with all objects
|
| 38 |
-
current_questions = {} # Dict to track questions for each object
|
| 39 |
-
|
| 40 |
-
while questions_asked < 10 and len(possible_objects) > 1:
|
| 41 |
-
question = None
|
| 42 |
-
for obj in possible_objects:
|
| 43 |
-
if obj not in current_questions:
|
| 44 |
-
current_questions[obj] = 0 # Start with the first question for this object
|
| 45 |
-
if current_questions[obj] < len(objects_and_questions[obj]):
|
| 46 |
-
# Get the next unanswered question for the object
|
| 47 |
-
question = objects_and_questions[obj][current_questions[obj]]
|
| 48 |
-
break
|
| 49 |
-
|
| 50 |
-
if not question:
|
| 51 |
-
break
|
| 52 |
-
|
| 53 |
-
# Ask the question
|
| 54 |
-
answer = st.radio(question, ('Yes', 'No'), key=questions_asked)
|
| 55 |
-
|
| 56 |
-
# Update the progress
|
| 57 |
-
if answer == 'Yes':
|
| 58 |
-
possible_objects = [obj for obj in possible_objects if objects_and_questions[obj][current_questions[obj]] == question]
|
| 59 |
-
else:
|
| 60 |
-
possible_objects = [obj for obj in possible_objects if objects_and_questions[obj][current_questions[obj]] != question]
|
| 61 |
-
|
| 62 |
-
# Move to the next question for the object
|
| 63 |
-
for obj in possible_objects:
|
| 64 |
-
current_questions[obj] += 1
|
| 65 |
-
|
| 66 |
-
questions_asked += 1
|
| 67 |
-
|
| 68 |
-
# After 10 questions or fewer, try to guess
|
| 69 |
-
if len(possible_objects) == 1:
|
| 70 |
-
st.write(f"I think you were thinking of a **{possible_objects[0]}**!")
|
| 71 |
-
elif len(possible_objects) > 1:
|
| 72 |
-
st.write("I couldn't guess your object with certainty. Maybe you can narrow it down a bit?")
|
| 73 |
-
else:
|
| 74 |
-
st.write("I couldn't guess anything based on the questions asked.")
|
| 75 |
-
|
| 76 |
-
# Main function for Streamlit
|
| 77 |
-
def main():
|
| 78 |
-
st.title("Guess My Thing Game")
|
| 79 |
-
|
| 80 |
-
# Start button
|
| 81 |
-
if st.button("Start Game"):
|
| 82 |
-
start_game()
|
| 83 |
-
|
| 84 |
-
if __name__ == "__main__":
|
| 85 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|