Skip to content

Kea Mokoena Assessment 002 - Submission#2

Open
KeaMokoena-codes wants to merge 1 commit into
micanipho:mainfrom
KeaMokoena-codes:main
Open

Kea Mokoena Assessment 002 - Submission#2
KeaMokoena-codes wants to merge 1 commit into
micanipho:mainfrom
KeaMokoena-codes:main

Conversation

@KeaMokoena-codes
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 is a student assessment submission implementing three analytics functions for list processing operations. The implementations attempt to solve problems related to filtering sales data, counting product codes, and calculating moving averages.

Key Changes:

  • Implementation of filter_sales_above_threshold() function with logic issues
  • Implementation of count_product_codes() function that ignores the prefix parameter
  • Implementation of calculate_moving_average() function with multiple calculation errors

Reviewed changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 11 comments.

File Description
analytics.py Added implementations for three analytics functions (filter_sales_above_threshold, count_product_codes, calculate_moving_average) with multiple logic errors and debug print statements
.vscode/settings.json Added VS Code Python testing configuration for unittest
pycache/test_analytics.cpython-313.pyc Compiled Python bytecode (auto-generated)
pycache/analytics.cpython-313.pyc Compiled Python bytecode (auto-generated)
Comments suppressed due to low confidence (3)

analytics.py:26

  • Print statement may execute during import.
print(filter_sales_above_threshold([200, 500, 75], 100)) 

analytics.py:52

  • Print statement may execute during import.
print(count_product_codes(["PROD-001", "PROD-002", "SERV-001"], "PROD"))

analytics.py:76

  • Print statement may execute during import.
print(calculate_moving_average([40, 50], 3))       

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

Comment thread analytics.py
Comment on lines +70 to +75
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
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 function doesn't round the result to 2 decimal places as required by the specifications. The return statement should use round(average, 2).

Suggested change
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
if not numbers:
return 0.0
window = numbers[-window_size:] if len(numbers) >= window_size else numbers
average = sum(window) / len(window)
return round(average, 2)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
else:
return []
return sales
print(filter_sales_above_threshold([200, 500, 75], 100))
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.

Debug print statement should be removed. This appears to be test/debug code that shouldn't be in the final submission.

Suggested change
print(filter_sales_above_threshold([200, 500, 75], 100))

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +47 to +50
if code.startswith("SERV"):
count += 1
elif code.startswith("PROD"):
count += 1
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 function ignores the prefix parameter and hardcodes checks for "SERV" and "PROD". This should use code.startswith(prefix) instead to count codes that start with the provided prefix parameter.

Suggested change
if code.startswith("SERV"):
count += 1
elif code.startswith("PROD"):
count += 1
if code.startswith(prefix):
count += 1

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +70 to +75
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
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.

sum(numbers[-1]) attempts to sum a single integer, which will cause a TypeError. This should be sum(numbers[-window_size:]) to get the sum of the last window_size elements.

Suggested change
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
if not numbers:
return 0.0
window = numbers[-window_size:] if window_size > 0 else []
if not window:
return 0.0
average = sum(window) / len(window)
return round(average, 2)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +76 to +77
print(calculate_moving_average([40, 50], 3))

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.

Debug print statement should be removed. This appears to be test/debug code that shouldn't be in the final submission.

Suggested change
print(calculate_moving_average([40, 50], 3))

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +20 to +25
for amount in sales:
if threshold > amount:
sales.append(amount)
else:
return []
return sales
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.

Returning an empty list when the first element exceeds the threshold is incorrect. The function should continue checking all elements and only return an empty list if no elements meet the criteria. This early return prevents the function from processing the entire list.

Suggested change
for amount in sales:
if threshold > amount:
sales.append(amount)
else:
return []
return sales
result = [amount for amount in sales if amount > threshold]
return result

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
elif code.startswith("PROD"):
count += 1
return count
print(count_product_codes(["PROD-001", "PROD-002", "SERV-001"], "PROD"))
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.

Debug print statement should be removed. This appears to be test/debug code that shouldn't be in the final submission.

Suggested change
print(count_product_codes(["PROD-001", "PROD-002", "SERV-001"], "PROD"))

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +70 to +75
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
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 loop unnecessarily iterates over all elements but doesn't use the iteration variable meaningfully. The average is recalculated on every iteration with the same result. The logic should calculate the average once, not in a loop.

Suggested change
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
if not numbers:
return 0.0
window = numbers[-window_size:] if len(numbers) >= window_size else numbers
average = sum(window) / len(window)
return round(average, 2)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +70 to +75
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
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.

When len(numbers) < window_size, dividing by window_size instead of len(numbers) produces an incorrect average. According to the requirements, if the list has fewer elements than window_size, the average should use all available elements, so the divisor should be len(numbers).

Suggested change
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
if not numbers:
return 0.0
if len(numbers) < window_size:
average = sum(numbers) / len(numbers)
else:
average = sum(numbers[-window_size:]) / window_size
return round(average, 2)

Copilot uses AI. Check for mistakes.
Comment thread analytics.py
Comment on lines +70 to +75
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
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 function doesn't handle the edge case of an empty list, which should return 0.0 according to the requirements. If numbers is empty, the function will fail when trying to return average since it won't be defined.

Suggested change
for _ in numbers:
if len(numbers) < window_size:
average = sum(numbers) / window_size
else:
average = sum(numbers[-1]) / window_size
return average
if not numbers:
return 0.0
window = numbers[-window_size:] if len(numbers) >= window_size else numbers
average = sum(window) / len(window)
return round(average, 2)

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