Skip to content

.#3

Open
proaisha127 wants to merge 1 commit into
micanipho:mainfrom
proaisha127:main
Open

.#3
proaisha127 wants to merge 1 commit into
micanipho:mainfrom
proaisha127:main

Conversation

@proaisha127
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements solutions for three coding exercises in analytics.py and adds a practice file. The PR attempts to implement list filtering, product code counting, and moving average calculation functions.

  • Implements filter_sales_above_threshold() with critical logic bugs
  • Implements count_product_codes() with correct logic but unreachable code
  • Implements calculate_moving_average() with incorrect window calculation logic

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
analytics.py Adds implementations for three functions (filter_sales_above_threshold, count_product_codes, calculate_moving_average) with multiple bugs and style issues
practise.py Adds a new practice/scratchpad file with a calculate_moving_average implementation that has similar bugs to analytics.py
.vscode/settings.json Configures Python unittest settings for the project
pycache/test_analytics.cpython-312.pyc Generated Python bytecode file from test execution
pycache/analytics.cpython-312.pyc Generated Python bytecode file from analytics module

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread analytics.py
Comment on lines +70 to +71
total=sum(numbers)
result=total/window_size
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
total=sum(numbers)
result=total/window_size
total = sum(numbers)
result = total / window_size

Copilot uses AI. Check for mistakes.
Comment thread practise.py
"""
# # TODO: Write your code here
# pass
total=sum(numbers)
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
total=sum(numbers)
total = sum(numbers)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +21 to +26
list=[]
for i in list:
if i>threshold:
return i
else:
return list
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
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 uses AI. Check for mistakes.
Comment thread practise.py
Comment on lines +72 to +76
# # TODO: Write your code here
# pass
total=sum(numbers)
result=total/window_size
return result
Copy link

Copilot AI Dec 1, 2025

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:

  1. Incorrect window calculation: The function sums all elements in numbers instead of only the last window_size elements. It should use numbers[-window_size:].
  2. Missing edge case handling: Returns ZeroDivisionError for empty lists instead of 0.0 as specified.
  3. Missing rounding: The result should be rounded to 2 decimal places using round(result, 2).
  4. Wrong logic for fewer elements: When the list has fewer elements than window_size, it incorrectly divides by window_size instead of the actual number of elements.
Suggested change
# # 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)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +22 to +24
for i in list:
if i>threshold:
return i
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name i is not descriptive for this context. Use a more meaningful name like sale or amount to improve code readability.

Suggested change
for i in list:
if i>threshold:
return i
for sale in list:
if sale>threshold:
return sale

Copilot uses AI. Check for mistakes.
Comment thread analytics.py

# # TODO: Write your code here
# pass
total=sum(numbers)
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
total=sum(numbers)
total = sum(numbers)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
@@ -34,6 +42,13 @@ def count_product_codes(codes: list, prefix: str):
"""
# TODO: Write your code here
pass
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
pass

Copilot uses AI. Check for mistakes.
Comment thread practise.py
# # TODO: Write your code here
# pass
total=sum(numbers)
result=total/window_size
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
result=total/window_size
result = total / window_size

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
# pass
list=[]
for i in list:
if i>threshold:
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
if i>threshold:
if i > threshold:

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +21 to +26
list=[]
for i in list:
if i>threshold:
return i
else:
return list
Copy link

Copilot AI Dec 1, 2025

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:

  1. Variable shadowing: Line 21 uses list as a variable name, which shadows Python's built-in list type.
  2. Iterating over empty list: Line 22 iterates over the newly created empty list, so the loop body never executes.
  3. Incorrect parameter usage: The function should iterate over the sales parameter, not the local list variable.
  4. Premature return: Lines 24 and 26 return immediately on the first iteration, preventing the function from collecting all qualifying values.
  5. 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.

Suggested change
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 uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants