Samanfatima563474 commited on
Commit
8c21fb3
·
verified ·
1 Parent(s): 10e6593

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -2
app.py CHANGED
@@ -62,7 +62,7 @@ curriculum = [
62
  {"module": "Mastering DSA - Stacks", "title": "Lesson 1: Stacks (LIFO)", "explanation": "A **stack** is a data structure that follows the LIFO (Last-In, First-Out) principle. In Python, a list can be used as a stack. You use `.append()` to add an item to the top ('push') and `.pop()` to remove the most recently added item ('pop').\n\n**Example:**\n```python\nstack = []\nstack.append('a') # stack is ['a']\nstack.append('b') # stack is ['a', 'b']\nitem = stack.pop() # item is 'b', stack is now ['a']\n```", "check": {"type": "mcq", "question": "Which principle does a stack follow?", "options": ["FIFO", "LIFO", "Random"], "answer": "LIFO"}},
63
  ]
64
 
65
- ### --- DATA: DEDICATED PRACTICE PROBLEMS (ALIGNED WITH LESSONS) --- ###
66
  practice_problems = [
67
  # --- Foundations (Baby Steps) ---
68
  {
@@ -89,7 +89,31 @@ practice_problems = [
89
  "check_type": "variable", "check_variable": "uppercase_name", "expected_result": "GOJRA",
90
  "background_knowledge": "Strings have many useful built-in methods. The `.upper()` method will return a new string where all characters are in uppercase. Remember to call it with parentheses, like `my_string.upper()`."
91
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  # --- Easy (Combining Concepts) ---
 
 
 
 
 
 
 
 
93
  {
94
  "title": "Easy: Count Positive Numbers",
95
  "concepts_covered": ["Lists", "Loops", "Operators"],
@@ -106,6 +130,71 @@ practice_problems = [
106
  "check_type": "variable", "check_variable": "long_words", "expected_result": ['python', 'excellent', 'window'],
107
  "background_knowledge": "To solve this, you'll need to loop through the `words` list. Inside the loop, you can find the length of each word using the `len()` function. If the length meets the condition, you can add that word to your `long_words` list using the `.append()` method."
108
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  ]
110
 
111
  ### --- HELPER & AI FUNCTIONS --- ###
@@ -169,7 +258,7 @@ def get_code_coaching(problem, user_code):
169
 
170
  ### --- GRADIO APP WITH TABS --- ###
171
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
172
- time_str = "Sunday, August 24, 2025 at 02:03 PM PKT"
173
 
174
  gr.Markdown(f"# Welcome to the CS Pathfinder\n*Current Location: Jhang, Punjab, Pakistan. Current Time: {time_str}*")
175
 
 
62
  {"module": "Mastering DSA - Stacks", "title": "Lesson 1: Stacks (LIFO)", "explanation": "A **stack** is a data structure that follows the LIFO (Last-In, First-Out) principle. In Python, a list can be used as a stack. You use `.append()` to add an item to the top ('push') and `.pop()` to remove the most recently added item ('pop').\n\n**Example:**\n```python\nstack = []\nstack.append('a') # stack is ['a']\nstack.append('b') # stack is ['a', 'b']\nitem = stack.pop() # item is 'b', stack is now ['a']\n```", "check": {"type": "mcq", "question": "Which principle does a stack follow?", "options": ["FIFO", "LIFO", "Random"], "answer": "LIFO"}},
63
  ]
64
 
65
+ ### --- DATA: DEDICATED PRACTICE PROBLEMS (EXPANDED & ALIGNED) --- ###
66
  practice_problems = [
67
  # --- Foundations (Baby Steps) ---
68
  {
 
89
  "check_type": "variable", "check_variable": "uppercase_name", "expected_result": "GOJRA",
90
  "background_knowledge": "Strings have many useful built-in methods. The `.upper()` method will return a new string where all characters are in uppercase. Remember to call it with parentheses, like `my_string.upper()`."
91
  },
92
+ {
93
+ "title": "Foundations: Reassign a Variable",
94
+ "concepts_covered": ["Variables"],
95
+ "problem_statement": "A variable `score` is initially set to 50. On the next line, update (reassign) the value of `score` to be 100.",
96
+ "starter_code": "score = 50\n\n# Your code here",
97
+ "check_type": "variable", "check_variable": "score", "expected_result": 100,
98
+ "background_knowledge": "To change the value of a variable, you simply assign a new value to it using the equals sign (`=`). The old value is forgotten."
99
+ },
100
+ {
101
+ "title": "Foundations: String Concatenation",
102
+ "concepts_covered": ["Variables", "Strings"],
103
+ "problem_statement": "You are given two string variables, `first_name` and `last_name`. Combine them to create a `full_name` with a space in between.",
104
+ "starter_code": "first_name = \"Ali\"\nlast_name = \"Khan\"\n\n# Your code here\nfull_name = ...",
105
+ "check_type": "variable", "check_variable": "full_name", "expected_result": "Ali Khan",
106
+ "background_knowledge": "You can join strings using the `+` operator. To add a space, you can concatenate a string that contains just a space: `\" \"`."
107
+ },
108
  # --- Easy (Combining Concepts) ---
109
+ {
110
+ "title": "Easy: Sum of List Elements",
111
+ "concepts_covered": ["Variables", "Lists", "Loops"],
112
+ "problem_statement": "You are given a list of numbers: `data = [10, 20, 30, 40]`. Write a `for` loop to calculate the sum of all the numbers in the list. Store the final result in a variable called `total`.",
113
+ "starter_code": "data = [10, 20, 30, 40]\ntotal = 0\n\n# Your code here",
114
+ "check_type": "variable", "check_variable": "total", "expected_result": 100,
115
+ "background_knowledge": "This is a classic introductory problem. You'll need to create a variable to keep track of the running total. Then, loop through each number in the list and add it to your total in each iteration."
116
+ },
117
  {
118
  "title": "Easy: Count Positive Numbers",
119
  "concepts_covered": ["Lists", "Loops", "Operators"],
 
130
  "check_type": "variable", "check_variable": "long_words", "expected_result": ['python', 'excellent', 'window'],
131
  "background_knowledge": "To solve this, you'll need to loop through the `words` list. Inside the loop, you can find the length of each word using the `len()` function. If the length meets the condition, you can add that word to your `long_words` list using the `.append()` method."
132
  },
133
+ {
134
+ "title": "Easy: Create a List of Word Lengths",
135
+ "concepts_covered": ["Lists", "Loops", "Strings"],
136
+ "problem_statement": "You have a list of words: `words = ['sky', 'is', 'blue']`. Create a new list called `lengths` that contains the length of each word.",
137
+ "starter_code": "words = ['sky', 'is', 'blue']\nlengths = []\n\n# Your code here",
138
+ "check_type": "variable", "check_variable": "lengths", "expected_result": [3, 2, 4],
139
+ "background_knowledge": "You will need to loop through the `words` list. In each iteration, calculate the length of the word using `len()` and then `.append()` that length to your `lengths` list."
140
+ },
141
+ {
142
+ "title": "Easy: Find Sum of Negative Numbers",
143
+ "concepts_covered": ["Lists", "Loops", "Operators"],
144
+ "problem_statement": "Given a list `data = [5, -2, -8, 4, -1]`, find the sum of only the negative numbers. Store the result in a variable called `negative_sum`.",
145
+ "starter_code": "data = [5, -2, -8, 4, -1]\nnegative_sum = 0\n\n# Your code here",
146
+ "check_type": "variable", "check_variable": "negative_sum", "expected_result": -11,
147
+ "background_knowledge": "This is similar to summing all elements, but with a condition. Loop through the list, and use an `if` statement to check if a number is less than 0. If it is, add it to your `negative_sum` variable."
148
+ },
149
+ # --- Medium (More Complex Logic) ---
150
+ {
151
+ "title": "Medium: Find the Maximum Number",
152
+ "concepts_covered": ["Lists", "Loops", "Operators"],
153
+ "problem_statement": "Given a list `numbers = [1, 5, 2, 9, 3, 8]`, find the largest number in the list **without using the built-in `max()` function**. Store your result in a variable called `largest_number`.",
154
+ "starter_code": "numbers = [1, 5, 2, 9, 3, 8]\n# Initialize with the first element\nlargest_number = numbers[0]\n\n# Your code here",
155
+ "check_type": "variable", "check_variable": "largest_number", "expected_result": 9,
156
+ "background_knowledge": "The key to this problem is to keep track of the biggest number you've seen *so far*. You start by assuming the first number is the largest. Then, you loop through the rest of the numbers, and if you find one that's bigger than your current `largest_number`, you update it."
157
+ },
158
+ {
159
+ "title": "Medium: Count Vowels in a String",
160
+ "concepts_covered": ["Strings", "Loops", "Operators"],
161
+ "problem_statement": "Given the string `sentence = \"learning python is fun\"`, count how many vowels (`a`, `e`, `i`, `o`, `u`) it contains. Store the result in a variable called `vowel_count`.",
162
+ "starter_code": "sentence = \"learning python is fun\"\nvowels = \"aeiou\"\nvowel_count = 0\n\n# Your code here",
163
+ "check_type": "variable", "check_variable": "vowel_count", "expected_result": 6,
164
+ "background_knowledge": "You can loop through each character of the `sentence`. Inside the loop, you need to check if the character is one of the vowels. A simple way is to use the `in` operator: `if char in vowels:`."
165
+ },
166
+ {
167
+ "title": "Medium: Remove Odd Numbers",
168
+ "concepts_covered": ["Lists", "Loops", "Operators"],
169
+ "problem_statement": "You are given a list of numbers `data = [1, 2, 3, 4, 5, 6]`. Create a new list called `even_numbers` that contains only the even numbers from the original list.",
170
+ "starter_code": "data = [1, 2, 3, 4, 5, 6]\neven_numbers = []\n\n# Your code here",
171
+ "check_type": "variable", "check_variable": "even_numbers", "expected_result": [2, 4, 6],
172
+ "background_knowledge": "You can check if a number is even using the modulo operator (`%`). A number is even if `number % 2 == 0`. Loop through the `data` list, check each number, and if it's even, `.append()` it to the `even_numbers` list."
173
+ },
174
+ {
175
+ "title": "Medium: Reverse a String with a Stack",
176
+ "concepts_covered": ["Strings", "Loops", "Stacks"],
177
+ "problem_statement": "Using the concepts of a stack (LIFO), reverse the string `text = \"hello\"`. 1. Push each character onto a list (our stack). 2. Pop each character off and join them to form the reversed string. Store the final result in `reversed_text`.",
178
+ "starter_code": "text = \"hello\"\nstack = []\nreversed_text = \"\"\n\n# Your code here",
179
+ "check_type": "variable", "check_variable": "reversed_text", "expected_result": "olleh",
180
+ "background_knowledge": "This problem demonstrates the LIFO (Last-In, First-Out) nature of stacks. You'll need two loops. The first loop iterates through the input string to `append()` (push) each character onto the `stack` list. The second loop should run as long as the stack is not empty, using `.pop()` to get the last character and add it to your `reversed_text` string."
181
+ },
182
+ {
183
+ "title": "Hard: Palindrome Checker",
184
+ "concepts_covered": ["Strings", "Operators"],
185
+ "problem_statement": "A palindrome is a word that reads the same forwards and backward, like 'racecar'. Write code to check if the string `word = \"madam\"` is a palindrome. Store your boolean result (`True` or `False`) in a variable called `is_palindrome`.",
186
+ "starter_code": "word = \"madam\"\nis_palindrome = False\n\n# Hint: You can compare a string to its reversed version.\n# How do you reverse a string? Slicing `[::-1]` is a common way.\n\n# Your code here",
187
+ "check_type": "variable", "check_variable": "is_palindrome", "expected_result": True,
188
+ "background_knowledge": "The most elegant way to solve this in Python is using string slicing. The slice `[::-1]` creates a reversed copy of a string. You can simply compare the original `word` with its reversed version. If they are equal (`==`), then it's a palindrome."
189
+ },
190
+ {
191
+ "title": "Hard: List Palindrome Checker",
192
+ "concepts_covered": ["Lists", "Operators"],
193
+ "problem_statement": "Check if the list `data = [1, 2, 3, 2, 1]` is a palindrome (reads the same forwards and backward). Store your boolean result (`True` or `False`) in a variable called `is_list_palindrome`.",
194
+ "starter_code": "data = [1, 2, 3, 2, 1]\nis_list_palindrome = False\n\n# Your code here",
195
+ "check_type": "variable", "check_variable": "is_list_palindrome", "expected_result": True,
196
+ "background_knowledge": "Just like strings, lists can also be reversed using slicing `[::-1]`. You can compare the original list to its reversed version to see if they are identical."
197
+ }
198
  ]
199
 
200
  ### --- HELPER & AI FUNCTIONS --- ###
 
258
 
259
  ### --- GRADIO APP WITH TABS --- ###
260
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
261
+ time_str = "Sunday, August 24, 2025 at 02:15 PM PKT"
262
 
263
  gr.Markdown(f"# Welcome to the CS Pathfinder\n*Current Location: Jhang, Punjab, Pakistan. Current Time: {time_str}*")
264