Done with the functions#8
Conversation
I couldnt do median and prime
There was a problem hiding this comment.
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_medianandis_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 = 0before the loop and usesum += num * iinside the loop to accumulate the total.
"""Learning Outcome: Functions"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for i in range(1, n + 1): | ||
| sum = i ** 2 | ||
| return sum |
There was a problem hiding this comment.
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.
| 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 |
| for i in range(1, n + 1): | ||
| sum = i ** 2 | ||
| return sum | ||
| if n < 0: | ||
| raise ValueError("n must be a postive integer") |
There was a problem hiding this comment.
The validation check is unreachable because it appears after the return statement. Move this check to the beginning of the function before any processing.
| 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 |
| sum = i ** 2 | ||
| return sum | ||
| if n < 0: | ||
| raise ValueError("n must be a postive integer") |
There was a problem hiding this comment.
Corrected spelling of 'postive' to 'positive'.
| raise ValueError("n must be a postive integer") | |
| raise ValueError("n must be a positive integer") |
| avg = sum(grades) / len(grades) | ||
| return "Pass" if avg >= min_pass else "Fail" | ||
| if not grades: | ||
| return "Fail" |
There was a problem hiding this comment.
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.
| 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" |
| average = sum(scores.values()) / len(scores) | ||
| below_average = [] | ||
| for subject, score in scores.items(): | ||
| if score < avg: |
There was a problem hiding this comment.
Variable avg is undefined; should be average to match the variable defined on line 16.
| if score < avg: | |
| if score < average: |
| for num in nums: | ||
| square = num ** 2 | ||
| return square | ||
| pass |
There was a problem hiding this comment.
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.
| for num in nums: | |
| square = num ** 2 | |
| return square | |
| pass | |
| squares = [] | |
| for num in nums: | |
| squares.append(num ** 2) | |
| return squares |
| total = sum(nums) | ||
| average = total / len(nums) | ||
| return (total, average) | ||
| if not nums: | ||
| return (0, 0) |
There was a problem hiding this comment.
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.
| 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) |
| for num in nums: | ||
| if num % 2 == 0: | ||
| return num | ||
| pass |
There was a problem hiding this comment.
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.
| 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 |
| pass | ||
|
|
||
| def reverse_string(input: str): | ||
| reversed_text = input("Enter Text: ") |
There was a problem hiding this comment.
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 = ''.
| reversed_text = input("Enter Text: ") | |
| reversed_text = '' |
| largest = nums[0] | ||
| for num in nums: | ||
| if num > largest: | ||
| largest = num | ||
| return largest | ||
|
|
||
| if not nums: | ||
| return None | ||
| pass | ||
|
|
There was a problem hiding this comment.
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.
| 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 |
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