Skip to content

Ayanda#5

Open
ayandadimpho wants to merge 2 commits into
micanipho:mainfrom
ayandadimpho:main
Open

Ayanda#5
ayandadimpho wants to merge 2 commits into
micanipho:mainfrom
ayandadimpho:main

Conversation

@ayandadimpho
Copy link
Copy Markdown

No description provided.

@FreakyJay1 FreakyJay1 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 contains attempted implementations of multiple Python functions focused on learning outcomes including functions, loops, data processing, and algorithms. However, the implementations contain numerous logic errors and bugs that prevent the functions from working correctly.

Key Issues:

  • Early return statements inside loops causing functions to only process first iteration
  • Functions overwriting their input parameters with empty collections
  • Incorrect variable references and logic errors throughout

Reviewed Changes

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

File Description
student_code.py Contains buggy implementations of educational Python functions with multiple logic errors, early returns in loops, and incorrect variable usage
.vscode/settings.json Adds VS Code configuration for Python unit testing

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

Comment thread student_code.py
@@ -1,5 +1,11 @@
"""Learning Outcome: Functions"""
def sum_of_squares(n: int):
if num <= 0:
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.

Variable name mismatch: the parameter is 'n' but the code references 'num'. This should be 'if n <= 0:'.

Suggested change
if num <= 0:
if n <= 0:

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +6 to +8
for num in range (1, n + 1):
sum += num * num
return sum
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 statement is inside the loop, causing the function to return after the first iteration. Move 'return sum' outside the loop to calculate the complete sum of squares.

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +25 to +27
min_pass = 75
grades = []

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 function parameters are immediately overwritten with hardcoded values, discarding the input arguments. Remove these lines to use the actual parameters passed to the function.

Suggested change
min_pass = 75
grades = []

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +28 to +32
for grade in grades:
if grade >= min_pass:
return "Pass"
else:
return "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.

The return statement inside the loop causes the function to return after checking only the first grade. This should likely accumulate results or return a list of pass/fail statuses for all grades.

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
pass

def calculate_cumulative_performance(scores: dict):
average = sum[scores]/ len[scores]
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.

Incorrect syntax: 'sum' and 'len' are functions and require parentheses, not square brackets. This should be 'sum(scores) / len(scores)'. Additionally, 'scores' is a dict, so you likely need 'scores.values()'.

Suggested change
average = sum[scores]/ len[scores]
average = sum(scores.values()) / len(scores.values())

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +316 to +318
nums = []
median = sum(nums) / 2
return median
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 'nums' parameter is overwritten with an empty list, and median calculation is incorrect (dividing sum by 2 instead of finding the middle value). Remove line 316 and implement proper median logic by sorting the list and finding the middle element(s).

Suggested change
nums = []
median = sum(nums) / 2
return median
if not nums:
raise ValueError("The list is empty.")
nums_sorted = sorted(nums)
n = len(nums_sorted)
mid = n // 2
if n % 2 == 1:
return float(nums_sorted[mid])
else:
return (nums_sorted[mid - 1] + nums_sorted[mid]) / 2

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

def reverse_string(input: str):

return reverse_string[::-1]
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.

Variable name error: 'reverse_string' is the function name, not the input parameter. This should be 'return input[::-1]'.

Suggested change
return reverse_string[::-1]
return input[::-1]

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
pass

def largest_number(nums: list[int]):
nums = []
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 input parameter 'nums' is overwritten with an empty list, discarding the actual input. Remove this line to process the provided list.

Suggested change
nums = []

Copilot uses AI. Check for mistakes.
Comment thread student_code.py
Comment on lines +363 to +367
for num in range(n):
if num // num == 1 and num // 1 == num:
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.

The prime checking logic is incorrect. The condition 'num // num == 1' will cause division by zero when num=0, and the logic doesn't properly test for prime numbers. A prime number should only be divisible by 1 and itself; implement proper divisibility testing.

Suggested change
for num in range(n):
if num // num == 1 and num // 1 == num:
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.
Comment thread student_code.py
Comment on lines +380 to +385
word_sentence = ""
char_count = 0

for char in word_sentence:
char_count += 1
return char_count
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 'word_sentence' parameter is overwritten with an empty string, making the loop never execute. The function should count occurrences of the specific character 'char_count' (second parameter) in 'word_sentence', not total character count. Remove lines 380-381 and implement proper character counting logic.

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