Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
|
4 |
+
st.set_page_config(page_title="Guess the Number Game ๐ฏ", page_icon="๐ฎ")
|
5 |
+
|
6 |
+
st.title("๐ฎ Guess the Number Game")
|
7 |
+
st.markdown("I'm thinking of a number between 1 and 100. Can you guess it?")
|
8 |
+
|
9 |
+
# Initialize the random number in session state
|
10 |
+
if "secret_number" not in st.session_state:
|
11 |
+
st.session_state.secret_number = random.randint(1, 100)
|
12 |
+
st.session_state.tries = 0
|
13 |
+
|
14 |
+
guess = st.number_input("Enter your guess", min_value=1, max_value=100, step=1)
|
15 |
+
|
16 |
+
if st.button("Guess"):
|
17 |
+
st.session_state.tries += 1
|
18 |
+
if guess < st.session_state.secret_number:
|
19 |
+
st.warning("Too low! Try a higher number.")
|
20 |
+
elif guess > st.session_state.secret_number:
|
21 |
+
st.warning("Too high! Try a lower number.")
|
22 |
+
else:
|
23 |
+
st.success(f"๐ Correct! You guessed it in {st.session_state.tries} tries.")
|
24 |
+
st.balloons()
|
25 |
+
if st.button("Play Again"):
|
26 |
+
st.session_state.secret_number = random.randint(1, 100)
|
27 |
+
st.session_state.tries = 0
|
28 |
+
else:
|
29 |
+
st.info("Make a guess and press the button!")
|
30 |
+
|