Skip to content

Done with the functions#8

Open
LatoyaMatai633k wants to merge 1 commit into
micanipho:mainfrom
LatoyaMatai633k:patch-1
Open

Done with the functions#8
LatoyaMatai633k wants to merge 1 commit into
micanipho:mainfrom
LatoyaMatai633k:patch-1

Conversation

@LatoyaMatai633k
Copy link
Copy Markdown

I couldnt do median and prime my mind is tired. please let me know if this is what you wanted? thanks for sending these exercises i was able to remind myself some of them

I couldnt do median and prime
@micanipho micanipho requested a review from Copilot October 27, 2025 14:36
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 represents a student's attempt at completing a Python programming exercise involving functions, loops, data processing, and algorithms. The student has implemented most of the required functions but acknowledges being unable to complete the find_median and is_prime functions.

Key Changes:

  • Implemented 20+ functions covering basic Python concepts including list operations, dictionary manipulation, and string transformations
  • Functions related to calculating statistics, filtering data, and analyzing performance trends have been added
  • Two functions (find_median and is_prime) remain unimplemented as noted in the PR description

Reviewed Changes

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

File Description
student_code.py Original template file with function stubs removed
Latoya's student_code.py New file containing student's implementations of the assigned functions
Comments suppressed due to low confidence (1)

Latoya's student_code.py:1

  • The function only returns the first multiple instead of the sum of all multiples. Initialize sum = 0 before the loop and use sum += num * i inside the loop to accumulate the total.
"""Learning Outcome: Functions"""

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

Comment on lines +3 to +5
for i in range(1, n + 1):
sum = i ** 2
return sum
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function only returns the square of the last number instead of the sum of all squares. Initialize sum = 0 before the loop and use sum += i ** 2 inside the loop to accumulate the total.

Suggested change
for i in range(1, n + 1):
sum = i ** 2
return sum
total = 0
for i in range(1, n + 1):
total += i ** 2
return total

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +7
for i in range(1, n + 1):
sum = i ** 2
return sum
if n < 0:
raise ValueError("n must be a postive integer")
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The validation check is unreachable because it appears after the return statement. Move this check to the beginning of the function before any processing.

Suggested change
for i in range(1, n + 1):
sum = i ** 2
return sum
if n < 0:
raise ValueError("n must be a postive integer")
if n < 0:
raise ValueError("n must be a postive integer")
for i in range(1, n + 1):
sum = i ** 2
return sum

Copilot uses AI. Check for mistakes.
sum = i ** 2
return sum
if n < 0:
raise ValueError("n must be a postive integer")
Copy link

Copilot AI Oct 27, 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
raise ValueError("n must be a postive integer")
raise ValueError("n must be a positive integer")

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +13
avg = sum(grades) / len(grades)
return "Pass" if avg >= min_pass else "Fail"
if not grades:
return "Fail"
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The empty list check is unreachable because it appears after the return statement. Move this validation to the beginning of the function to prevent division by zero on line 10.

Suggested change
avg = sum(grades) / len(grades)
return "Pass" if avg >= min_pass else "Fail"
if not grades:
return "Fail"
if not grades:
return "Fail"
avg = sum(grades) / len(grades)
return "Pass" if avg >= min_pass else "Fail"

Copilot uses AI. Check for mistakes.
average = sum(scores.values()) / len(scores)
below_average = []
for subject, score in scores.items():
if score < avg:
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

Variable avg is undefined; should be average to match the variable defined on line 16.

Suggested change
if score < avg:
if score < average:

Copilot uses AI. Check for mistakes.
Comment on lines +111 to +114
for num in nums:
square = num ** 2
return square
pass
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function returns only the square of the first number instead of a list of all squares. Initialize an empty list before the loop, append each square to it, and return the list after the loop.

Suggested change
for num in nums:
square = num ** 2
return square
pass
squares = []
for num in nums:
squares.append(num ** 2)
return squares

Copilot uses AI. Check for mistakes.
Comment on lines +128 to +132
total = sum(nums)
average = total / len(nums)
return (total, average)
if not nums:
return (0, 0)
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The empty list check is unreachable because it appears after the return statement. Move this validation to the beginning of the function to prevent division by zero on line 129.

Suggested change
total = sum(nums)
average = total / len(nums)
return (total, average)
if not nums:
return (0, 0)
if not nums:
return (0, 0)
total = sum(nums)
average = total / len(nums)
return (total, average)

Copilot uses AI. Check for mistakes.
Comment on lines +143 to +146
for num in nums:
if num % 2 == 0:
return num
pass
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function returns only the first even number instead of a list of all even numbers. Initialize an empty list before the loop, append even numbers to it, and return the list after the loop.

Suggested change
for num in nums:
if num % 2 == 0:
return num
pass
even_nums = []
for num in nums:
if num % 2 == 0:
even_nums.append(num)
return even_nums

Copilot uses AI. Check for mistakes.
pass

def reverse_string(input: str):
reversed_text = input("Enter Text: ")
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

Line 166 incorrectly calls the input() built-in function which prompts for user input, overwriting the function parameter. Initialize reversed_text as an empty string instead: reversed_text = ''.

Suggested change
reversed_text = input("Enter Text: ")
reversed_text = ''

Copilot uses AI. Check for mistakes.
Comment on lines +174 to +183
largest = nums[0]
for num in nums:
if num > largest:
largest = num
return largest

if not nums:
return None
pass

Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The empty list check is unreachable because it appears after the return statement. Move this validation to the beginning of the function to prevent an IndexError on line 174.

Suggested change
largest = nums[0]
for num in nums:
if num > largest:
largest = num
return largest
if not nums:
return None
pass
if not nums:
return None
largest = nums[0]
for num in nums:
if num > largest:
largest = num
return largest

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