--Hazel Sibhuku#11
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements solutions for a series of Python programming exercises covering functions, loops, and basic algorithms. The changes replace placeholder pass statements with working implementations for most functions, though several remain incomplete.
Key Changes:
- Implemented basic mathematical functions (sum of squares, even/odd number generation)
- Added loop-based data processing functions (filtering, transformations, aggregations)
- Included test code with print statements for manual verification
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| student_code.py | Implements multiple function solutions with test cases; adds section markers between questions |
| pract.py | Contains scratch work and experimental code for some of the exercises |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for i in grades: | ||
| if ave >= min_pass: | ||
| return "Pass" | ||
| else: | ||
| return "Fail" | ||
| return |
There was a problem hiding this comment.
The loop iterates over grades but the condition checks 'ave >= min_pass' which is independent of 'i'. The function will always return on the first iteration, making the loop unnecessary. The logic should check the average once outside the loop.
| for i in grades: | |
| if ave >= min_pass: | |
| return "Pass" | |
| else: | |
| return "Fail" | |
| return | |
| if ave >= min_pass: | |
| return "Pass" | |
| else: | |
| return "Fail" |
| return "Pass" | ||
| else: | ||
| return "Fail" | ||
| return |
There was a problem hiding this comment.
This unreachable return statement will never execute since the function always returns in the loop above. This line should be removed.
| return |
|
|
||
| return list | ||
|
|
||
| print(skip_num(2, 10)) |
There was a problem hiding this comment.
This line calls 'skip_num' but should call 'break_test' based on the function context. The incorrect function is being tested here.
| print(skip_num(2, 10)) | |
| print(break_test(2, 10)) |
| Parameters: | ||
| nums (list): A list of integers. | ||
| for i in nums: | ||
| if i >= 0: |
There was a problem hiding this comment.
The condition checks for non-negative numbers (>= 0) but the function name is 'count_positive_numbers'. Zero is not a positive number. The condition should be 'i > 0'.
| if i >= 0: | |
| if i > 0: |
| for i in nums: | ||
| if i%2==0: | ||
| pass #do something | ||
| else: | ||
| return sum(nums)/len(nums) |
There was a problem hiding this comment.
The logic for finding the median is incorrect. This implementation returns the mean (average) on the first odd number, which is not how median is calculated. The median requires sorting the list and finding the middle value(s).
| def reverse_string(input: str): | ||
| """ | ||
| Reverse the given string. | ||
| string = input |
There was a problem hiding this comment.
The variable 'string' is assigned but never used. This line should be removed as it serves no purpose.
| string = input |
| for i in nums: | ||
| i = max(nums) |
There was a problem hiding this comment.
The loop unnecessarily iterates through all numbers and repeatedly calculates max(nums). The max value should be computed once outside the loop: 'return max(nums)' or handle empty list appropriately.
| if n%2 != 0: | ||
| return True | ||
| else: | ||
| return False |
There was a problem hiding this comment.
The prime number check is incorrect. This only checks if a number is odd, but not all odd numbers are prime (e.g., 9, 15, 21). A proper prime check requires testing divisibility by all numbers from 2 to sqrt(n).
No description provided.