K0RB1 commited on
Commit
f7c14ac
·
1 Parent(s): 674e800

save all changes

Browse files
Files changed (1) hide show
  1. app.py +20 -32
app.py CHANGED
@@ -1,15 +1,12 @@
1
  import random
2
  import streamlit as st
3
-
4
 
5
  st.title("Welcome To Person Guessing Game!!")
6
- st.header("Guess Well Play Well")
7
-
8
 
9
  st.write("Here Is Your Choices: Gian, Kirby, Francys, JK, Cielo, Arki, Basti, Mico, and Jhay.")
10
- st.write("I will describe a person, and you need to guess who it is by thier characteristics.")
11
- def guess():
12
 
 
13
  people = {
14
  "Gian": ["Smart", "small", "hyper"],
15
  "Kirby": ["small", "loyal", "Loves badminton"],
@@ -22,37 +19,28 @@ def guess():
22
  "Jhay": ["kind", "Always making others laugh", "Loves to make friends laugh"]
23
  }
24
 
25
-
26
-
27
- names = list(people.keys())
28
- characteristics = list(people.values())
29
-
30
-
31
- index = random.randint(0, len(names) - 1)
32
- chosen_name = names[index]
33
- description = characteristics[index]
34
 
35
- attempts = 0
36
- max_attempts = 5
37
 
38
- st.write("\nHere's the description for the person:")
39
- st.write(f"{description}")
40
 
41
- while attempts < max_attempts:
42
- guess = st.text_input("WHO DO YOU THINK IT IS?? ").strip()
43
- attempts += 1
44
-
45
-
46
- if guess.lower() == chosen_name.lower():
47
- st.write(f"CONGRATULATIONS! YOU GUESSED IT CORRECTLY. IT'S {chosen_name}.")
48
- break
49
- else:
50
- if attempts > max_attempts:
51
- st.write("That's not correct. Try again!")
52
- else:
53
- st.write(f"SORRY, YOUR'E RUN OUT OF ATTEMPS. THE CORRECT ANSWER WAS {chosen_name}.")
54
 
55
- st.write(f"THANKS FOR PlAYING!!")
 
 
 
 
56
 
 
57
 
58
  guess()
 
1
  import random
2
  import streamlit as st
 
3
 
4
  st.title("Welcome To Person Guessing Game!!")
5
+ st.header("I will describe a person and you need to guess who it is by their characteristics")
 
6
 
7
  st.write("Here Is Your Choices: Gian, Kirby, Francys, JK, Cielo, Arki, Basti, Mico, and Jhay.")
 
 
8
 
9
+ def guess():
10
  people = {
11
  "Gian": ["Smart", "small", "hyper"],
12
  "Kirby": ["small", "loyal", "Loves badminton"],
 
19
  "Jhay": ["kind", "Always making others laugh", "Loves to make friends laugh"]
20
  }
21
 
22
+ if 'chosen_name' not in st.session_state:
23
+ names = list(people.keys())
24
+ index = random.randint(0, len(names) - 1)
25
+ st.session_state.chosen_name = names[index]
26
+ st.session_state.description = people[st.session_state.chosen_name]
27
+ st.session_state.attempts = 0
28
+ st.session_state.max_attempts = 5
 
 
29
 
30
+ st.write(f"Here's the description for the person: {', '.join(st.session_state.description)}")
 
31
 
32
+ guess = st.text_input("Who Do You Think It Is??")
 
33
 
34
+ if guess.lower() == st.session_state.chosen_name.lower():
35
+ st.success(f"CONGRATULATIONS!!! YOU GUESSED IT CORRECTLY! IT IS {st.session_state.chosen_name}")
36
+ st.stop() # Stop the app after a correct guess
 
 
 
 
 
 
 
 
 
 
37
 
38
+ if st.session_state.attempts < st.session_state.max_attempts - 1:
39
+ st.warning("That's Not Correct. Please Try Again.")
40
+ else:
41
+ st.error(f"Sorry, You're Out Of Attempts. The Correct Answer Was {st.session_state.chosen_name}")
42
+ st.stop() # Stop the app after the game ends
43
 
44
+ st.session_state.attempts += 1
45
 
46
  guess()