K0RB1's picture
updated
7bd5976
import random
import streamlit as st
st.title("Welcome To Person Guessing Game!!")
st.header("I will describe a person and you need to guess who it is by their characteristics")
st.write("Here Is Your Choices: Gian, Kirby, Francys, JK, Cielo, Arki, Basti, Mico, and Jhay.")
def guess():
people = {
"Gian": ["Smart", "small", "hyper"],
"Kirby": ["small", "loyal", "Loves badminton"],
"Francys": ["serious", "smart", "quiet"],
"JK": ["tall", "foot fetish", "talkative"],
"Cielo": ["quiet", "Loves to watch peppapig", "Enjoys editing"],
"Arki": ["talkative", "Loves blue by yung kai", "enjoys coding"],
"Basti": ["Music lover", "tall", "Enjoys jamming with friends"],
"Mico": ["smart", "Good at editing", "Enjoys coding"],
"Jhay": ["kind", "Always making others laugh", "Loves to make friends laugh"]
}
if 'chosen_name' not in st.session_state:
names = list(people.keys())
index = random.randint(0, len(names) - 1)
st.session_state.chosen_name = names[index]
st.session_state.description = people[st.session_state.chosen_name]
st.session_state.attempts = 0
st.session_state.max_attempts = 5
st.write(f"Here's the description for the person: {', '.join(st.session_state.description)}")
a, b = st.columns(2)
guess = st.text_input("Who Do You Think It Is??")
submit = a.button("submit")
clear = b.button("clear")
if submit:
if guess.lower() == st.session_state.chosen_name.lower():
st.success(f"CONGRATULATIONS!!! You Guessed It Correctly It Is {st.session_state.chosen_name}.")
st.stop()
if st.session_state.attempts < st.session_state.max_attempts -1:
RA = st.session_state.max_attempts - st.session_state.attempts
st.warning(f"That's Not Correct. You Have {RA} attempts left .")
else:
st.error(f"Sorry, You're Out Of Attempts. The Correct Answer Was {st.session_state.chosen_name}.")
st.stop()
if clear:
for key in ['chosen_name', 'description', 'attempts']:
if key in st.session_state:
del st.session_state[key]
st.session_state.attempts += 1
guess()