-
Notifications
You must be signed in to change notification settings - Fork 12
. #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
. #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "python.testing.unittestArgs": [ | ||
| "-v", | ||
| "-s", | ||
| ".", | ||
| "-p", | ||
| "test_*.py" | ||
| ], | ||
| "python.testing.pytestEnabled": false, | ||
| "python.testing.unittestEnabled": true | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,9 +16,17 @@ def filter_sales_above_threshold(sales: list, threshold: int): | |||||||||||||||||||||||||||||||||||||||||||||
| - Return empty list if no values qualify | ||||||||||||||||||||||||||||||||||||||||||||||
| - Use a loop or list comprehension | ||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||
| # TODO: Write your code here | ||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # # TODO: Write your code here | ||||||||||||||||||||||||||||||||||||||||||||||
| # pass | ||||||||||||||||||||||||||||||||||||||||||||||
| list=[] | ||||||||||||||||||||||||||||||||||||||||||||||
| for i in list: | ||||||||||||||||||||||||||||||||||||||||||||||
| if i>threshold: | ||||||||||||||||||||||||||||||||||||||||||||||
| return i | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+24
|
||||||||||||||||||||||||||||||||||||||||||||||
| for i in list: | |
| if i>threshold: | |
| return i | |
| for sale in list: | |
| if sale>threshold: | |
| return sale |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using list as a variable name shadows Python's built-in list type, which is a common anti-pattern and violates Python naming best practices. Use a descriptive name like result or filtered_sales instead.
| list=[] | |
| for i in list: | |
| if i>threshold: | |
| return i | |
| else: | |
| return list | |
| filtered_sales = [] | |
| for sale in sales: | |
| if sale > threshold: | |
| filtered_sales.append(sale) | |
| return filtered_sales |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation has multiple critical bugs:
- Variable shadowing: Line 21 uses
listas a variable name, which shadows Python's built-inlisttype. - Iterating over empty list: Line 22 iterates over the newly created empty list, so the loop body never executes.
- Incorrect parameter usage: The function should iterate over the
salesparameter, not the locallistvariable. - Premature return: Lines 24 and 26 return immediately on the first iteration, preventing the function from collecting all qualifying values.
- Wrong return type: The function returns individual integers instead of a list of all qualifying values.
The correct implementation should iterate over sales, collect all values greater than threshold in a result list, and return that list after checking all values.
| list=[] | |
| for i in list: | |
| if i>threshold: | |
| return i | |
| else: | |
| return list | |
| result = [] | |
| for sale in sales: | |
| if sale > threshold: | |
| result.append(sale) | |
| return result |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unreachable code: The pass statement on line 44 is never executed because the code after it (lines 45-49) will always run first. Since lines 45-49 contain the actual implementation, this pass statement should be removed.
| pass |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spacing around the assignment operator. Should be total = sum(numbers) according to PEP 8 style guidelines.
| total=sum(numbers) | |
| total = sum(numbers) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spacing around the assignment and division operators. Should be result = total / window_size according to PEP 8 style guidelines.
| total=sum(numbers) | |
| result=total/window_size | |
| total = sum(numbers) | |
| result = total / window_size |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation has multiple bugs that fail the documented requirements:
- Incorrect window calculation: The function sums all elements in
numbersinstead of only the lastwindow_sizeelements. It should usenumbers[-window_size:]. - Missing edge case handling: Returns
ZeroDivisionErrorfor empty lists instead of0.0as specified. - Missing rounding: The result should be rounded to 2 decimal places using
round(result, 2). - Wrong logic for fewer elements: When the list has fewer elements than
window_size, it incorrectly divides bywindow_sizeinstead of the actual number of elements.
| total=sum(numbers) | |
| result=total/window_size | |
| return result | |
| if not numbers: | |
| return 0.0 | |
| window = numbers[-window_size:] if window_size > 0 else [] | |
| avg = sum(window) / len(window) if window else 0.0 | |
| return round(avg, 2) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||||||||||||||||||
| # # def filter_sales_above_threshold(sales: list, threshold: int): | ||||||||||||||||||||||
| # # """ | ||||||||||||||||||||||
| # # QUESTION 1 | ||||||||||||||||||||||
| # # ---------------------------------------- | ||||||||||||||||||||||
| # # Given a list of sales amounts (integers), return a NEW list containing | ||||||||||||||||||||||
| # # only values above the threshold. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # # Example: filter_sales_above_threshold([100, 250, 75, 300], 150) → [250, 300] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # # Logic: | ||||||||||||||||||||||
| # # - Do NOT modify the original list | ||||||||||||||||||||||
| # # - Return empty list if no values qualify | ||||||||||||||||||||||
| # # - Use a loop or list comprehension | ||||||||||||||||||||||
| # # """ | ||||||||||||||||||||||
| # # # TODO: Write your code here | ||||||||||||||||||||||
| # # pass | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # # list=[] | ||||||||||||||||||||||
| # # for i in list: | ||||||||||||||||||||||
| # # if i>threshold: | ||||||||||||||||||||||
| # # return i | ||||||||||||||||||||||
| # # else: | ||||||||||||||||||||||
| # # return list | ||||||||||||||||||||||
| # # print(filter_sales_above_threshold([100, 250, 75, 300], 150)) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # # def count_product_codes(codes: list, prefix: str): | ||||||||||||||||||||||
| # # """ | ||||||||||||||||||||||
| # # QUESTION 2 | ||||||||||||||||||||||
| # # ---------------------------------------- | ||||||||||||||||||||||
| # # Given a list of product codes (strings) and a prefix (string), | ||||||||||||||||||||||
| # # count how many codes START with the given prefix (case-sensitive). | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # # Example: count_product_codes(["PROD-001", "PROD-002", "SERV-001"], "PROD") → 2 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # # Logic: | ||||||||||||||||||||||
| # # - Return 0 if no matches found | ||||||||||||||||||||||
| # # """ | ||||||||||||||||||||||
| # # # # TODO: Write your code here | ||||||||||||||||||||||
| # # # pass | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # # prefix=0 | ||||||||||||||||||||||
| # # count=(["PROD-001", "PROD-002", "SERV-001"], "PROD") | ||||||||||||||||||||||
| # # count_prefix=count[1] | ||||||||||||||||||||||
| # # for i in count: | ||||||||||||||||||||||
| # # prefix=prefix+1 | ||||||||||||||||||||||
| # # print(prefix) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # count = 0 | ||||||||||||||||||||||
| # for code in codes: | ||||||||||||||||||||||
| # if code.startswith(prefix): | ||||||||||||||||||||||
| # count += 1 | ||||||||||||||||||||||
| # return count | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def calculate_moving_average(numbers: list, window_size: int): | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
| QUESTION 3 | ||||||||||||||||||||||
| ---------------------------------------- | ||||||||||||||||||||||
| Calculate the average of the LAST window_size elements in the list. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Example: calculate_moving_average([10, 20, 30, 40, 50], 3) → 40.0 | ||||||||||||||||||||||
| (average of last 3: 30, 40, 50) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Logic: | ||||||||||||||||||||||
| - If the list has fewer elements than window_size, use all available elements | ||||||||||||||||||||||
| - Return the average as a float rounded to 2 decimal places | ||||||||||||||||||||||
| - Return 0.0 for empty list | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
| # # TODO: Write your code here | ||||||||||||||||||||||
| # pass | ||||||||||||||||||||||
| total=sum(numbers) | ||||||||||||||||||||||
|
||||||||||||||||||||||
| total=sum(numbers) | |
| total = sum(numbers) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spacing around the assignment and division operators. Should be result = total / window_size according to PEP 8 style guidelines.
| result=total/window_size | |
| result = total / window_size |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation has multiple bugs that fail the documented requirements:
- Incorrect window calculation: The function sums all elements in
numbersinstead of only the lastwindow_sizeelements. It should usenumbers[-window_size:]. - Missing edge case handling: Returns
ZeroDivisionErrorfor empty lists instead of0.0as specified. - Missing rounding: The result should be rounded to 2 decimal places using
round(result, 2). - Wrong logic for fewer elements: When the list has fewer elements than
window_size, it incorrectly divides bywindow_sizeinstead of the actual number of elements.
| # # TODO: Write your code here | |
| # pass | |
| total=sum(numbers) | |
| result=total/window_size | |
| return result | |
| if not numbers: | |
| return 0.0 | |
| window = numbers[-window_size:] | |
| avg = sum(window) / len(window) | |
| return round(avg, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spacing around the comparison operator. Should be
if i > threshold:according to PEP 8 style guidelines.