Mahrukhh commited on
Commit
47e72df
ยท
verified ยท
1 Parent(s): 2349578

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -95
app.py CHANGED
@@ -2,188 +2,170 @@ import streamlit as st
2
  import random
3
  import time
4
 
5
- # ------------------ Setup ------------------
6
  st.set_page_config(page_title="๐ŸŽฎ Mini Game Arcade", layout="centered")
7
  st.title("๐ŸŽฎ Mini Game Arcade")
8
- st.caption("Welcome to the ultimate game zone! Select a game and start playing instantly.")
 
9
 
10
- # ------------------ Game List ------------------
11
  games = [
12
- "๐ŸŽฎ Rock Paper Scissors",
13
- "๐Ÿ”ข Guess the Number",
14
- "๐Ÿ”ค Word Scramble",
15
- "๐Ÿ˜„ Emoji Quiz",
16
- "๐Ÿช™ Coin Toss",
17
- "๐ŸŽฒ Dice Roll",
18
- "๐Ÿ‘ป Hangman Mini",
19
- "โž• Math Quiz",
20
- "โŒจ๏ธ Quick Typing Challenge",
21
- "๐Ÿง  Memory Test",
22
- "๐Ÿงฎ Multiplication Duel",
23
- "๐Ÿ“ Estimate Length"
24
  ]
25
 
26
- selected_game = st.selectbox("Choose your game ๐Ÿ‘‡", games)
 
27
 
28
  # ------------------ Game Functions ------------------
29
 
30
  def rock_paper_scissors():
31
  st.subheader("๐Ÿชจ Rock Paper Scissors")
32
- st.markdown("Choose your move below. The computer will randomly choose too!")
33
- user = st.radio("Your move:", ["Rock", "Paper", "Scissors"])
34
  if st.button("Play"):
35
  computer = random.choice(["Rock", "Paper", "Scissors"])
36
- st.write(f"๐Ÿ’ป Computer chose: **{computer}**")
37
  if user == computer:
38
  st.info("It's a draw!")
39
  elif (user == "Rock" and computer == "Scissors") or \
40
  (user == "Paper" and computer == "Rock") or \
41
  (user == "Scissors" and computer == "Paper"):
42
- st.success("You win! ๐ŸŽ‰")
43
  else:
44
- st.error("You lose ๐Ÿ˜ข")
45
 
46
  def guess_the_number():
47
- st.subheader("๐Ÿ”ข Guess the Number")
48
- st.markdown("Guess a number between 1 and 10.")
49
  number = random.randint(1, 10)
50
- guess = st.number_input("Enter your guess:", 1, 10)
51
  if st.button("Check"):
52
  if guess == number:
53
- st.success("Correct! ๐ŸŽฏ")
54
  else:
55
- st.error(f"Wrong! The number was {number}")
56
 
57
  def word_scramble():
58
- st.subheader("๐Ÿ”ค Word Scramble")
59
- words = ["streamlit", "python", "developer", "banana", "arcade"]
60
  word = random.choice(words)
61
- scrambled = ''.join(random.sample(word, len(word)))
62
- st.markdown(f"Unscramble this word: **{scrambled}**")
63
  guess = st.text_input("Your guess:")
64
  if st.button("Submit"):
65
  if guess.lower() == word:
66
- st.success("Correct! ๐Ÿง ")
67
  else:
68
- st.error(f"Wrong! It was **{word}**")
69
 
70
  def emoji_quiz():
71
- st.subheader("๐Ÿ˜„ Emoji Quiz")
72
  quiz = {
73
  "๐Ÿ•๐Ÿ”๐ŸŸ": "Fast Food",
74
- "๐Ÿš—๐Ÿ’จ": "Speed",
75
  "๐Ÿฑ๐Ÿถ": "Pets",
76
- "โœˆ๏ธ๐ŸŒ": "Travel",
77
- "๐ŸŽ“๐Ÿ“š": "Education",
78
- "โšฝ๐Ÿ€๐Ÿˆ": "Sports"
79
  }
80
  emojis, answer = random.choice(list(quiz.items()))
81
- st.markdown(f"What do these emojis mean? **{emojis}**")
82
  guess = st.text_input("Your answer:")
83
  if st.button("Check Answer"):
84
- if guess.strip().lower() == answer.lower():
85
- st.success("Correct! ๐ŸŽ‰")
86
  else:
87
- st.error(f"The answer was: **{answer}**")
88
 
89
  def coin_toss():
90
  st.subheader("๐Ÿช™ Coin Toss")
91
- if st.button("Toss the coin"):
92
  result = random.choice(["Heads", "Tails"])
93
  st.success(f"It's **{result}**!")
94
 
95
  def dice_roll():
96
  st.subheader("๐ŸŽฒ Dice Roll")
97
- if st.button("Roll the Dice"):
98
  result = random.randint(1, 6)
99
  st.success(f"You rolled a **{result}**!")
100
 
101
  def hangman_mini():
102
  st.subheader("๐Ÿ‘ป Hangman (Mini)")
103
- word = random.choice(["pen", "dog", "cup", "sun"])
104
- st.info(f"The word has **{len(word)}** letters.")
 
105
  guess = st.text_input("Guess the word:")
106
  if st.button("Reveal"):
107
  if guess.lower() == word:
108
- st.success("You guessed it!")
109
  else:
110
  st.error(f"The word was **{word}**")
111
 
112
  def math_quiz():
113
  st.subheader("โž• Math Quiz")
114
- a, b = random.randint(1, 20), random.randint(1, 20)
 
115
  st.write(f"What is {a} + {b}?")
116
  answer = st.number_input("Your answer:", step=1)
117
  if st.button("Submit"):
118
  if answer == a + b:
119
  st.success("Correct!")
120
  else:
121
- st.error(f"Wrong! It's {a + b}")
122
 
123
  def quick_typing():
124
  st.subheader("โŒจ๏ธ Quick Typing Challenge")
125
- word = random.choice(["elephant", "keyboard", "stream", "python"])
126
- st.markdown(f"Type this exactly: **{word}**")
127
- typed = st.text_input("Your input:")
128
  if st.button("Submit"):
129
- if typed == word:
130
- st.success("Correct!")
131
  else:
132
- st.error("Try again!")
133
 
134
  def memory_test():
135
  st.subheader("๐Ÿง  Memory Test")
136
  nums = random.sample(range(1, 100), 5)
137
- st.markdown("Remember these numbers:")
138
  st.code(nums)
139
- time.sleep(3)
140
- guess = st.number_input("Enter any number you remember:", step=1)
 
141
  if st.button("Check"):
142
  if guess in nums:
143
  st.success("Correct!")
144
  else:
145
  st.error(f"Oops! Numbers were: {nums}")
146
 
147
- def multiplication_duel():
148
- st.subheader("๐Ÿงฎ Multiplication Duel")
149
- x, y = random.randint(2, 10), random.randint(2, 10)
150
- st.write(f"What is {x} ร— {y}?")
151
- answer = st.number_input("Answer:", step=1)
152
- if st.button("Submit"):
153
- if answer == x * y:
154
- st.success("Correct!")
155
- else:
156
- st.error(f"Wrong! Itโ€™s {x * y}")
157
-
158
- def estimate_length():
159
- st.subheader("๐Ÿ“ Estimate the Length")
160
- real = random.randint(10, 100)
161
- st.write("Estimate the length (in cm) of an imaginary object:")
162
- guess = st.slider("Your estimate:", 0, 150)
163
- if st.button("Submit"):
164
- error = abs(real - guess)
165
- st.success(f"Actual length: {real}cm. Your error: {error}cm")
166
-
167
  # ------------------ Game Dispatcher ------------------
168
 
169
- game_map = {
170
- "๐ŸŽฎ Rock Paper Scissors": rock_paper_scissors,
171
- "๐Ÿ”ข Guess the Number": guess_the_number,
172
- "๐Ÿ”ค Word Scramble": word_scramble,
173
- "๐Ÿ˜„ Emoji Quiz": emoji_quiz,
174
- "๐Ÿช™ Coin Toss": coin_toss,
175
- "๐ŸŽฒ Dice Roll": dice_roll,
176
- "๐Ÿ‘ป Hangman Mini": hangman_mini,
177
- "โž• Math Quiz": math_quiz,
178
- "โŒจ๏ธ Quick Typing Challenge": quick_typing,
179
- "๐Ÿง  Memory Test": memory_test,
180
- "๐Ÿงฎ Multiplication Duel": multiplication_duel,
181
- "๐Ÿ“ Estimate Length": estimate_length
182
- }
183
-
184
- # Run the selected game
185
- game_map[selected_game]()
 
 
 
186
 
187
  # ------------------ Footer ------------------
188
  st.markdown("---")
189
- st.caption("๐ŸŽ‰ Built with Streamlit | ๐Ÿ’ก Fun for all ages!")
 
2
  import random
3
  import time
4
 
5
+ # ------------------ Page Setup ------------------
6
  st.set_page_config(page_title="๐ŸŽฎ Mini Game Arcade", layout="centered")
7
  st.title("๐ŸŽฎ Mini Game Arcade")
8
+ st.caption("Enjoy a variety of mini games with a clean, fun interface!")
9
+ st.markdown("---")
10
 
11
+ # ------------------ Game Selector ------------------
12
  games = [
13
+ "Rock Paper Scissors",
14
+ "Guess the Number",
15
+ "Word Scramble",
16
+ "Emoji Quiz",
17
+ "Coin Toss",
18
+ "Dice Roll",
19
+ "Hangman (Mini)",
20
+ "Math Quiz",
21
+ "Quick Typing Challenge",
22
+ "Memory Test"
 
 
23
  ]
24
 
25
+ selected_game = st.selectbox("๐Ÿ•น๏ธ Pick a game to play", games)
26
+ st.markdown("---")
27
 
28
  # ------------------ Game Functions ------------------
29
 
30
  def rock_paper_scissors():
31
  st.subheader("๐Ÿชจ Rock Paper Scissors")
32
+ user = st.radio("Your move:", ["Rock", "Paper", "Scissors"], horizontal=True)
 
33
  if st.button("Play"):
34
  computer = random.choice(["Rock", "Paper", "Scissors"])
35
+ st.write(f"Computer chose: **{computer}**")
36
  if user == computer:
37
  st.info("It's a draw!")
38
  elif (user == "Rock" and computer == "Scissors") or \
39
  (user == "Paper" and computer == "Rock") or \
40
  (user == "Scissors" and computer == "Paper"):
41
+ st.success("You win!")
42
  else:
43
+ st.error("You lose!")
44
 
45
  def guess_the_number():
46
+ st.subheader("๐Ÿ”น Guess the Number (1-10)")
 
47
  number = random.randint(1, 10)
48
+ guess = st.number_input("Enter your guess:", 1, 10, step=1)
49
  if st.button("Check"):
50
  if guess == number:
51
+ st.success("Correct! ๐ŸŽ‰")
52
  else:
53
+ st.error(f"Wrong! It was {number}")
54
 
55
  def word_scramble():
56
+ st.subheader("๐ŸŒค๏ธ Word Scramble")
57
+ words = ["python", "arcade", "streamlit", "banana", "gamer"]
58
  word = random.choice(words)
59
+ scrambled = "".join(random.sample(word, len(word)))
60
+ st.write(f"Unscramble this word: **{scrambled}**")
61
  guess = st.text_input("Your guess:")
62
  if st.button("Submit"):
63
  if guess.lower() == word:
64
+ st.success("Correct!")
65
  else:
66
+ st.error(f"Nope! The word was **{word}**")
67
 
68
  def emoji_quiz():
69
+ st.subheader("๐Ÿ˜ Emoji Quiz")
70
  quiz = {
71
  "๐Ÿ•๐Ÿ”๐ŸŸ": "Fast Food",
72
+ "๐Ÿš—๐Ÿšจ": "Speed",
73
  "๐Ÿฑ๐Ÿถ": "Pets",
74
+ "โœˆ๏ธ๐ŸŒ": "Travel"
 
 
75
  }
76
  emojis, answer = random.choice(list(quiz.items()))
77
+ st.write(f"What do these emojis mean? {emojis}")
78
  guess = st.text_input("Your answer:")
79
  if st.button("Check Answer"):
80
+ if guess.lower() == answer.lower():
81
+ st.success("Correct!")
82
  else:
83
+ st.error(f"Correct answer was **{answer}**")
84
 
85
  def coin_toss():
86
  st.subheader("๐Ÿช™ Coin Toss")
87
+ if st.button("Toss"):
88
  result = random.choice(["Heads", "Tails"])
89
  st.success(f"It's **{result}**!")
90
 
91
  def dice_roll():
92
  st.subheader("๐ŸŽฒ Dice Roll")
93
+ if st.button("Roll"):
94
  result = random.randint(1, 6)
95
  st.success(f"You rolled a **{result}**!")
96
 
97
  def hangman_mini():
98
  st.subheader("๐Ÿ‘ป Hangman (Mini)")
99
+ words = ["sun", "pen", "dog", "cup", "cat"]
100
+ word = random.choice(words)
101
+ st.info(f"Hint: The word has {len(word)} letters.")
102
  guess = st.text_input("Guess the word:")
103
  if st.button("Reveal"):
104
  if guess.lower() == word:
105
+ st.success("Correct!")
106
  else:
107
  st.error(f"The word was **{word}**")
108
 
109
  def math_quiz():
110
  st.subheader("โž• Math Quiz")
111
+ a = random.randint(1, 20)
112
+ b = random.randint(1, 20)
113
  st.write(f"What is {a} + {b}?")
114
  answer = st.number_input("Your answer:", step=1)
115
  if st.button("Submit"):
116
  if answer == a + b:
117
  st.success("Correct!")
118
  else:
119
+ st.error(f"Wrong! It was **{a + b}**")
120
 
121
  def quick_typing():
122
  st.subheader("โŒจ๏ธ Quick Typing Challenge")
123
+ word = random.choice(["elephant", "keyboard", "arcade", "stream", "python"])
124
+ st.info(f"Type this word exactly: **{word}**")
125
+ user_input = st.text_input("Start typing:")
126
  if st.button("Submit"):
127
+ if user_input == word:
128
+ st.success("Well done!")
129
  else:
130
+ st.error("Mismatch! Try again.")
131
 
132
  def memory_test():
133
  st.subheader("๐Ÿง  Memory Test")
134
  nums = random.sample(range(1, 100), 5)
135
+ st.info("Remember these numbers:")
136
  st.code(nums)
137
+ time.sleep(2)
138
+ st.write("Now enter any one number you remember:")
139
+ guess = st.number_input("Enter a number:", step=1)
140
  if st.button("Check"):
141
  if guess in nums:
142
  st.success("Correct!")
143
  else:
144
  st.error(f"Oops! Numbers were: {nums}")
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  # ------------------ Game Dispatcher ------------------
147
 
148
+ if selected_game == "Rock Paper Scissors":
149
+ rock_paper_scissors()
150
+ elif selected_game == "Guess the Number":
151
+ guess_the_number()
152
+ elif selected_game == "Word Scramble":
153
+ word_scramble()
154
+ elif selected_game == "Emoji Quiz":
155
+ emoji_quiz()
156
+ elif selected_game == "Coin Toss":
157
+ coin_toss()
158
+ elif selected_game == "Dice Roll":
159
+ dice_roll()
160
+ elif selected_game == "Hangman (Mini)":
161
+ hangman_mini()
162
+ elif selected_game == "Math Quiz":
163
+ math_quiz()
164
+ elif selected_game == "Quick Typing Challenge":
165
+ quick_typing()
166
+ elif selected_game == "Memory Test":
167
+ memory_test()
168
 
169
  # ------------------ Footer ------------------
170
  st.markdown("---")
171
+ st.markdown("<center>Made with โค๏ธ for fun and learning.</center>", unsafe_allow_html=True)