File size: 1,737 Bytes
b8b3c17
 
7a7c857
b8b3c17
7a7c857
 
 
 
 
 
 
 
 
26ddeff
7a7c857
 
 
26ddeff
7a7c857
 
 
26ddeff
7a7c857
 
 
26ddeff
7a7c857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8fb62eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import streamlit as st

# Function to start the guessing process
def start_game():
    st.title("Mind-Reading Number Game")
    
    # Instructions for the user
    st.write("Welcome to the Mind-Reading Number Game!")
    st.write("Please think of a number between 1 and 100, but do not tell me what it is.")
    st.write("Then, follow the instructions carefully.")
    
    # Step 1: Ask the user to perform a series of operations
    st.write("Step 1: Multiply your number by 2.")
    number_1 = st.number_input("Enter your result after multiplying by 2", min_value=2, step=1, key="number_1")
    
    # Step 2: Add 8 to the result
    st.write("Step 2: Now, add 8 to the result.")
    number_2 = st.number_input("Enter your result after adding 8", min_value=10, step=1, key="number_2")
    
    # Step 3: Divide the result by 2
    st.write("Step 3: Divide the result by 2.")
    number_3 = st.number_input("Enter your result after dividing by 2", min_value=5, step=1, key="number_3")
    
    # Step 4: Subtract the original number you thought of
    st.write("Step 4: Now, subtract the original number you thought of.")
    number_4 = st.number_input("Enter your result after subtracting your original number", min_value=0, step=1, key="number_4")

    # Final calculation to guess the number
    if number_1 and number_2 and number_3 and number_4:
        # The number the user thought of can be found as follows:
        guessed_number = number_4 - 4  # The final result is the user's number minus 4
        
        st.write(f"Your original number is: **{guessed_number}**!")

    # Button to restart the game
    if st.button("Restart Game"):
        start_game()
        st.experimental_rerun()

# Start the game
start_game()