keerthuAi commited on
Commit
cb21542
ยท
verified ยท
1 Parent(s): 96f5111

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -6
app.py CHANGED
@@ -23,6 +23,30 @@ quiz_questions = [
23
  "options": ["7", "52", "2"],
24
  "answer": "7",
25
  "hint": "What is 5 + 2?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
27
  ]
28
 
@@ -70,9 +94,15 @@ def prev_quiz():
70
  # ๐Ÿ”ค 2. WORD SCRAMBLE GAME
71
  # ------------------------
72
 
73
- scramble_words = [("python", "A popular programming language"),
74
- ("loop", "Used to repeat code"),
75
- ("print", "Outputs something on screen")]
 
 
 
 
 
 
76
 
77
  def scramble_word(word):
78
  return ''.join(random.sample(word, len(word)))
@@ -99,7 +129,10 @@ dice_challenges = [
99
  "๐Ÿ’ก Create a variable and assign it your name",
100
  "๐Ÿ’ก Write code to add 2 + 3 and print it",
101
  "๐Ÿ’ก Use a loop to print numbers from 1 to 5",
102
- "๐Ÿ’ก Print your favorite color 3 times"
 
 
 
103
  ]
104
 
105
  def roll_dice():
@@ -137,12 +170,46 @@ def check_fairy_ans(ans):
137
  else:
138
  return "โŒ Not quite, try again!"
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  # ------------------------
141
  # ๐ŸŽจ UI
142
  # ------------------------
143
 
144
  with gr.Blocks(theme=gr.themes.Base(primary_hue="purple", secondary_hue="pink")) as app:
145
- gr.Markdown("## ๐Ÿง’โœจ Welcome to Python FunLand! ๐ŸŽฎ Learn by Playing")
146
 
147
  with gr.Tabs():
148
  with gr.TabItem("๐ŸŽฏ Guess the Output"):
@@ -186,4 +253,22 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue="purple", secondary_hue="pink"))
186
  fairy_result = gr.Textbox(label="Result", interactive=False)
187
  gr.Button("โœ… Submit").click(fn=check_fairy_ans, inputs=fairy_input, outputs=fairy_result)
188
 
189
- app.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  "options": ["7", "52", "2"],
24
  "answer": "7",
25
  "hint": "What is 5 + 2?"
26
+ },
27
+ {
28
+ "code": 'print(10 / 2)',
29
+ "options": ["5", "2", "20"],
30
+ "answer": "5",
31
+ "hint": "What is 10 divided by 2?"
32
+ },
33
+ {
34
+ "code": 'x = "Python"\nprint(x[0])',
35
+ "options": ["P", "y", "t"],
36
+ "answer": "P",
37
+ "hint": "What is the first letter of 'Python'?"
38
+ },
39
+ {
40
+ "code": 'x = [1, 2, 3]\nprint(x[1])',
41
+ "options": ["2", "3", "1"],
42
+ "answer": "2",
43
+ "hint": "Which number is at the second position in the list?"
44
+ },
45
+ {
46
+ "code": 'x = "Code"\nprint(x[::-1])',
47
+ "options": ["edoC", "Code", "CdeO"],
48
+ "answer": "edoC",
49
+ "hint": "What does slicing the string backwards give?"
50
  }
51
  ]
52
 
 
94
  # ๐Ÿ”ค 2. WORD SCRAMBLE GAME
95
  # ------------------------
96
 
97
+ scramble_words = [
98
+ ("python", "A popular programming language"),
99
+ ("loop", "Used to repeat code"),
100
+ ("print", "Outputs something on screen"),
101
+ ("variable", "Stores data values"),
102
+ ("function", "Encapsulates code into reusable blocks"),
103
+ ("list", "A collection of items"),
104
+ ("string", "A sequence of characters")
105
+ ]
106
 
107
  def scramble_word(word):
108
  return ''.join(random.sample(word, len(word)))
 
129
  "๐Ÿ’ก Create a variable and assign it your name",
130
  "๐Ÿ’ก Write code to add 2 + 3 and print it",
131
  "๐Ÿ’ก Use a loop to print numbers from 1 to 5",
132
+ "๐Ÿ’ก Print your favorite color 3 times",
133
+ "๐Ÿ’ก Write a program to check if a number is even or odd",
134
+ "๐Ÿ’ก Create a list and add 3 items to it",
135
+ "๐Ÿ’ก Write a function that takes two numbers and returns their sum"
136
  ]
137
 
138
  def roll_dice():
 
170
  else:
171
  return "โŒ Not quite, try again!"
172
 
173
+ # ------------------------
174
+ # ๐Ÿ’ป 6. SIMPLE CALCULATOR
175
+ # ------------------------
176
+
177
+ def add(x, y):
178
+ return x + y
179
+
180
+ def subtract(x, y):
181
+ return x - y
182
+
183
+ def multiply(x, y):
184
+ return x * y
185
+
186
+ def divide(x, y):
187
+ if y != 0:
188
+ return x / y
189
+ return "โŒ Cannot divide by zero!"
190
+
191
+ # ------------------------
192
+ # ๐ŸŽจ 7. GUESS THE NUMBER
193
+ # ------------------------
194
+
195
+ target_number = random.randint(1, 100)
196
+
197
+ def guess_number(guess):
198
+ global target_number
199
+ if guess < target_number:
200
+ return "โฌ†๏ธ Try a higher number!"
201
+ elif guess > target_number:
202
+ return "โฌ‡๏ธ Try a lower number!"
203
+ else:
204
+ target_number = random.randint(1, 100) # Reset after correct guess
205
+ return "๐ŸŽ‰ Correct! Well done!"
206
+
207
  # ------------------------
208
  # ๐ŸŽจ UI
209
  # ------------------------
210
 
211
  with gr.Blocks(theme=gr.themes.Base(primary_hue="purple", secondary_hue="pink")) as app:
212
+ gr.Markdown("## ๐Ÿง’โœจ Welcome to Python FunLand! ๐ŸŽฎ Learn Python by Playing")
213
 
214
  with gr.Tabs():
215
  with gr.TabItem("๐ŸŽฏ Guess the Output"):
 
253
  fairy_result = gr.Textbox(label="Result", interactive=False)
254
  gr.Button("โœ… Submit").click(fn=check_fairy_ans, inputs=fairy_input, outputs=fairy_result)
255
 
256
+ with gr.TabItem("๐Ÿ’ป Simple Calculator"):
257
+ gr.Markdown("๐Ÿงฎ Let's do some math!")
258
+ num1 = gr.Number(label="Enter first number")
259
+ num2 = gr.Number(label="Enter second number")
260
+ operation = gr.Radio(choices=["Add", "Subtract", "Multiply", "Divide"], label="Choose Operation")
261
+ calc_result = gr.Textbox(label="Result", interactive=False)
262
+ gr.Button("โœ… Calculate").click(fn=lambda n1, n2, op: {
263
+ "Add": add(n1, n2),
264
+ "Subtract": subtract(n1, n2),
265
+ "Multiply": multiply(n1, n2),
266
+ "Divide": divide(n1, n2)
267
+ }[operation], inputs=[num1, num2, operation], outputs=calc_result)
268
+
269
+ with gr.TabItem("๐ŸŽฏ Guess the Number"):
270
+ gr.Markdown("๐ŸŽฎ Guess the number between 1 and 100!")
271
+ number_guess = gr.Number(label="Your Guess", interactive=True)
272
+ guess_result = gr.Textbox(label="Result", interactive=False)
273
+ gr.Button("โœ… Check Guess").click
274
+