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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -74
app.py CHANGED
@@ -2,66 +2,70 @@ import streamlit as st
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.markdown("Choose a game from the list and have fun!")
9
 
10
- # ------------------ Game Selector ------------------
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
  ]
23
 
24
- selected_game = st.selectbox("๐Ÿ•น๏ธ Pick a game to play", games)
25
 
26
  # ------------------ Game Functions ------------------
27
 
28
  def rock_paper_scissors():
29
  st.subheader("๐Ÿชจ Rock Paper Scissors")
30
- user = st.radio("Choose your move:", ["Rock", "Paper", "Scissors"])
 
31
  if st.button("Play"):
32
  computer = random.choice(["Rock", "Paper", "Scissors"])
33
- st.write(f"Computer chose **{computer}**")
34
  if user == computer:
35
- st.success("It's a draw!")
36
  elif (user == "Rock" and computer == "Scissors") or \
37
  (user == "Paper" and computer == "Rock") or \
38
  (user == "Scissors" and computer == "Paper"):
39
- st.success("You win!")
40
  else:
41
- st.error("You lose!")
42
 
43
  def guess_the_number():
44
- st.subheader("๐Ÿ”ข Guess the Number (1-10)")
 
45
  number = random.randint(1, 10)
46
- guess = st.number_input("Your guess:", 1, 10, step=1)
47
  if st.button("Check"):
48
  if guess == number:
49
- st.success("Correct! ๐ŸŽ‰")
50
  else:
51
- st.error(f"Wrong! It was {number}")
52
 
53
  def word_scramble():
54
  st.subheader("๐Ÿ”ค Word Scramble")
55
- words = ["python", "arcade", "streamlit", "banana", "gamer"]
56
  word = random.choice(words)
57
- scrambled = "".join(random.sample(word, len(word)))
58
- st.write(f"Unscramble this word: **{scrambled}**")
59
  guess = st.text_input("Your guess:")
60
  if st.button("Submit"):
61
  if guess.lower() == word:
62
- st.success("Correct!")
63
  else:
64
- st.error(f"Nope! The word was **{word}**")
65
 
66
  def emoji_quiz():
67
  st.subheader("๐Ÿ˜„ Emoji Quiz")
@@ -69,101 +73,117 @@ def emoji_quiz():
69
  "๐Ÿ•๐Ÿ”๐ŸŸ": "Fast Food",
70
  "๐Ÿš—๐Ÿ’จ": "Speed",
71
  "๐Ÿฑ๐Ÿถ": "Pets",
72
- "โœˆ๏ธ๐ŸŒ": "Travel"
 
 
73
  }
74
  emojis, answer = random.choice(list(quiz.items()))
75
- st.write(f"What do these emojis mean? {emojis}")
76
  guess = st.text_input("Your answer:")
77
  if st.button("Check Answer"):
78
- if guess.lower() == answer.lower():
79
- st.success("Correct!")
80
  else:
81
- st.error(f"The correct answer was **{answer}**")
82
 
83
  def coin_toss():
84
  st.subheader("๐Ÿช™ Coin Toss")
85
- if st.button("Toss Coin"):
86
  result = random.choice(["Heads", "Tails"])
87
- st.write(f"๐Ÿช™ It's **{result}**!")
88
 
89
  def dice_roll():
90
  st.subheader("๐ŸŽฒ Dice Roll")
91
- if st.button("Roll Dice"):
92
  result = random.randint(1, 6)
93
- st.write(f"๐ŸŽฒ You rolled a **{result}**!")
94
 
95
  def hangman_mini():
96
  st.subheader("๐Ÿ‘ป Hangman (Mini)")
97
- words = ["sun", "pen", "dog", "cup", "cat"]
98
- word = random.choice(words)
99
- st.write(f"The word has {len(word)} letters.")
100
  guess = st.text_input("Guess the word:")
101
  if st.button("Reveal"):
102
  if guess.lower() == word:
103
- st.success("Correct!")
104
  else:
105
  st.error(f"The word was **{word}**")
106
 
107
  def math_quiz():
108
  st.subheader("โž• Math Quiz")
109
- a = random.randint(1, 20)
110
- b = random.randint(1, 20)
111
  st.write(f"What is {a} + {b}?")
112
  answer = st.number_input("Your answer:", step=1)
113
  if st.button("Submit"):
114
  if answer == a + b:
115
  st.success("Correct!")
116
  else:
117
- st.error(f"Wrong! The answer is **{a + b}**")
118
 
119
  def quick_typing():
120
  st.subheader("โŒจ๏ธ Quick Typing Challenge")
121
- word = random.choice(["elephant", "keyboard", "arcade", "stream", "python"])
122
- st.write(f"Type this word exactly: **{word}**")
123
- user_input = st.text_input("Start typing:")
124
  if st.button("Submit"):
125
- if user_input == word:
126
- st.success("Well done!")
127
  else:
128
- st.error("Mismatch! Try again.")
129
 
130
  def memory_test():
131
  st.subheader("๐Ÿง  Memory Test")
132
  nums = random.sample(range(1, 100), 5)
133
- st.write("Remember these numbers:")
134
  st.code(nums)
135
  time.sleep(3)
136
- st.write("Now enter any one number you remember:")
137
- guess = st.number_input("Enter a number:", step=1)
138
  if st.button("Check"):
139
  if guess in nums:
140
  st.success("Correct!")
141
  else:
142
  st.error(f"Oops! Numbers were: {nums}")
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  # ------------------ Game Dispatcher ------------------
145
 
146
- if selected_game == "Rock Paper Scissors":
147
- rock_paper_scissors()
148
- elif selected_game == "Guess the Number":
149
- guess_the_number()
150
- elif selected_game == "Word Scramble":
151
- word_scramble()
152
- elif selected_game == "Emoji Quiz":
153
- emoji_quiz()
154
- elif selected_game == "Coin Toss":
155
- coin_toss()
156
- elif selected_game == "Dice Roll":
157
- dice_roll()
158
- elif selected_game == "Hangman (Mini)":
159
- hangman_mini()
160
- elif selected_game == "Math Quiz":
161
- math_quiz()
162
- elif selected_game == "Quick Typing Challenge":
163
- quick_typing()
164
- elif selected_game == "Memory Test":
165
- memory_test()
166
 
167
  # ------------------ Footer ------------------
168
  st.markdown("---")
169
- st.markdown("Made with โค๏ธ for fun and learning.")
 
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")
 
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!")