Skip to content

Cebolwethu mzanywa test#4

Open
CebolwethuMzanywa wants to merge 4 commits into
micanipho:mainfrom
CebolwethuMzanywa:main
Open

Cebolwethu mzanywa test#4
CebolwethuMzanywa wants to merge 4 commits into
micanipho:mainfrom
CebolwethuMzanywa:main

Conversation

@CebolwethuMzanywa
Copy link
Copy Markdown

No description provided.

@micanipho micanipho requested a review from Copilot October 21, 2025 12:11
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 PR implements multiple Python functions that were previously placeholders (pass statements). The changes add implementations for mathematical calculations, list/dictionary processing, and basic algorithm problems.

Key Changes:

  • Implemented mathematical functions (sum of squares, finding median, checking prime numbers)
  • Added data processing functions (filtering, counting, averaging)
  • Implemented control flow functions (break/continue patterns, iteration logic)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread student_code.py
sum += i **2
return sum
except ValueError:
return f"Enter a postive number"
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'postive' to 'positive'.

Suggested change
return f"Enter a postive number"
return f"Enter a positive number"

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +15 to +21
try:
sum = 0
for i in range(1, n + 1):
sum += i **2
return sum
except ValueError:
return f"Enter a postive number"
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The try-except block doesn't match the documented behavior. The function should raise ValueError for negative integers, but the current implementation will never trigger the except block since range() doesn't raise ValueError. Input validation should check if n < 0 and raise ValueError explicitly.

Suggested change
try:
sum = 0
for i in range(1, n + 1):
sum += i **2
return sum
except ValueError:
return f"Enter a postive number"
if n < 0:
raise ValueError("n must be a non-negative integer")
sum = 0
for i in range(1, n + 1):
sum += i **2
return sum

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
count += i

if count/len(grades) >= min_pass:
return f"pass"
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Using f-string for a static string is unnecessary. Return the plain string "Pass" instead (note: should be capitalized "Pass" to match the docstring specification).

Suggested change
return f"pass"
return "Pass"

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +40 to +42
return f"pass"
else:
return f"fail"
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Using f-string for a static string is unnecessary. Return the plain string "Fail" instead (note: should be capitalized "Fail" to match the docstring specification).

Suggested change
return f"pass"
else:
return f"fail"
return "Pass"
else:
return "Fail"

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +65 to 68
my_dict[average_score] = list_below_average

return my_dict

Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The return dictionary structure is incorrect. According to the docstring, it should return a dictionary with keys like "average_score" and "below_average", not use the numeric average_score value as a key. Expected structure: {"average_score": average_score, "below_average": list_below_average}.

Suggested change
my_dict[average_score] = list_below_average
return my_dict
return {"average_score": average_score, "below_average": list_below_average}

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
"""
pass
sum = 0
for i in tuple(elements):
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Converting to tuple doesn't remove duplicates as required by the function's purpose. Use set(elements) instead of tuple(elements) to sum only unique elements.

Suggested change
for i in tuple(elements):
for i in set(elements):

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
"""
pass
my_list = []
for i in range(1, length):
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Range is off by one. Should be range(1, length + 1) to include all integers from 1 to length as specified in the docstring.

Suggested change
for i in range(1, length):
for i in range(1, length + 1):

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +343 to +348
my_dict = {}
for word in words:
count = words.count(word)
my_dict[word] = count

return my_dict
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Calling words.count(word) inside a loop over the same list results in O(n²) time complexity. Use a more efficient approach by incrementing counts in a single pass through the list.

Suggested change
my_dict = {}
for word in words:
count = words.count(word)
my_dict[word] = count
return my_dict
from collections import Counter
my_dict = Counter(words)
return dict(my_dict)

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +417 to +421
max_num = 0
for num in nums:
if max_num < num:
max_num = num

Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Initializing max_num to 0 fails for lists containing only negative numbers. For an empty list, the function returns 0 instead of None as documented. Should check if list is empty first and return None, otherwise initialize max_num to the first element or use max(nums).

Suggested change
max_num = 0
for num in nums:
if max_num < num:
max_num = num
if not nums:
return None
max_num = nums[0]
for num in nums[1:]:
if max_num < num:
max_num = num

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +434 to +438
for i in range(2, n):
if n % i != 0:
return True
else:
return False
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Prime number logic is incorrect. The function returns True on the first non-divisor, which is wrong. It should check all numbers from 2 to n-1 (or sqrt(n) for efficiency) and only return True if none divide n evenly. Also, numbers less than 2 should return False.

Suggested change
for i in range(2, n):
if n % i != 0:
return True
else:
return False
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True

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