I tried really#12
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements multiple student exercise functions that were previously stubbed with pass statements. The changes include implementations for mathematical operations, list manipulations, string processing, and statistical calculations.
Key changes:
- Implementation of 20+ functions including sum calculations, list filtering, performance evaluation, and string manipulation
- Addition of
mathandstatisticsmodule imports - Inclusion of VS Code testing configuration for unittest framework
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 17 comments.
| File | Description |
|---|---|
| student_code.py | Implements all previously stubbed functions with working logic for calculations, filtering, and data processing |
| .vscode/settings.json | Adds unittest configuration for Python testing in VS Code |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| dict = {} | ||
| for i in grades: | ||
| if i >= min_pass: | ||
| return f"{i} Pass" | ||
| else: | ||
| return f"{i} Fail" |
There was a problem hiding this comment.
The function returns immediately on the first grade instead of calculating the average of all grades as specified in the docstring. The function should compute the average of all grades and compare it to min_pass.
| dict = {} | |
| for i in grades: | |
| if i >= min_pass: | |
| return f"{i} Pass" | |
| else: | |
| return f"{i} Fail" | |
| if not grades: | |
| return "Fail" | |
| average = sum(grades) / len(grades) | |
| if average >= min_pass: | |
| return "Pass" | |
| else: | |
| return "Fail" |
| lis = [] | ||
| for i in scores.values(): | ||
| lis.append(i) | ||
| return sum(lis)/len(lis) |
There was a problem hiding this comment.
The return statement is inside the loop, causing the function to return after processing only the first value. Move the return statement outside the loop. Additionally, the function should return a dictionary with average and below-average subjects according to the docstring, not just a number.
| lis = [] | |
| for i in scores.values(): | |
| lis.append(i) | |
| return sum(lis)/len(lis) | |
| if not scores: | |
| return {"average": 0, "below_average_subjects": []} | |
| average = sum(scores.values()) / len(scores) | |
| below_average_subjects = [subject for subject, score in scores.items() if score < average] | |
| return {"average": average, "below_average_subjects": below_average_subjects} |
| dictionary = {} | ||
| positve = False | ||
| negative = False | ||
| neutral = False | ||
| for i in scores: | ||
| if i > 0: | ||
| positve = True | ||
| return positve | ||
| elif i < 0: | ||
| negative = True | ||
| return negative | ||
| elif i == 0: | ||
| neutral = True | ||
| return neutral |
There was a problem hiding this comment.
The function returns on the first score instead of analyzing the trend across all scores. The function should determine the overall trend based on all values in the list and return a dictionary with 'trend' and 'improvement' keys as specified in the docstring.
| dictionary = {} | |
| positve = False | |
| negative = False | |
| neutral = False | |
| for i in scores: | |
| if i > 0: | |
| positve = True | |
| return positve | |
| elif i < 0: | |
| negative = True | |
| return negative | |
| elif i == 0: | |
| neutral = True | |
| return neutral | |
| if not scores or len(scores) == 1: | |
| # Not enough data to determine trend | |
| return {'trend': 'neutral', 'improvement': False} | |
| increases = 0 | |
| decreases = 0 | |
| for prev, curr in zip(scores, scores[1:]): | |
| if curr > prev: | |
| increases += 1 | |
| elif curr < prev: | |
| decreases += 1 | |
| if increases > decreases: | |
| trend = 'positive' | |
| improvement = True | |
| elif decreases > increases: | |
| trend = 'negative' | |
| improvement = False | |
| else: | |
| trend = 'neutral' | |
| improvement = False | |
| return {'trend': trend, 'improvement': improvement} |
| lis = [] | ||
| for i in range(1,length+1): | ||
| if i != n: | ||
| print(lis.append(i)) |
There was a problem hiding this comment.
The print statement wraps lis.append(i) which returns None. Remove the print wrapper and just use lis.append(i).
| print(lis.append(i)) | |
| lis.append(i) |
| for i in range(1,length): | ||
| if i <= n: | ||
| print(lis.append(i)) |
There was a problem hiding this comment.
The print statement wraps lis.append(i) which returns None. Remove the print wrapper. Additionally, the logic should break when encountering n (not <=), and it should be if i < n or use a break statement when i == n.
| for i in range(1,length): | |
| if i <= n: | |
| print(lis.append(i)) | |
| for i in range(1, length): | |
| if i == n: | |
| break | |
| lis.append(i) |
| for num in nums: | ||
| if num % 2 == 0: | ||
| even.append(num) | ||
| print(even) |
There was a problem hiding this comment.
The function prints the list but doesn't return it. According to the docstring, the function should return a list. Change print(even) to return even.
| print(even) | |
| return even |
| pass | ||
|
|
||
| median = statistics.median(nums) | ||
| print(median) |
There was a problem hiding this comment.
The function prints the median but doesn't return it. According to the docstring, the function should return a float or int. Change print(median) to return median.
| print(median) | |
| return median |
| largest = max(nums) | ||
| if not nums: | ||
| return None#stuck here | ||
| print(largest) |
There was a problem hiding this comment.
The empty list check happens after calling max(nums), which will raise a ValueError on an empty list. Move the if not nums check to the beginning of the function before calling max(). Also, change print(largest) to return largest.
| largest = max(nums) | |
| if not nums: | |
| return None#stuck here | |
| print(largest) | |
| if not nums: | |
| return None | |
| largest = max(nums) | |
| return largest |
| if n < 2: | ||
| return False | ||
| if n == 2: | ||
| return True |
There was a problem hiding this comment.
The function doesn't check if n is even before starting the loop at 3 with step 2. Add a check if n % 2 == 0: return False after the n == 2 check to handle even numbers correctly.
| return True | |
| return True | |
| if n % 2 == 0: | |
| return False |
| for word in word_sentence.lower(): | ||
| if word == char_count: | ||
| count += 1 | ||
| return print(count) |
There was a problem hiding this comment.
The expression return print(count) returns None since print() returns None. Change this to return count to return the integer count as specified in the docstring.
| return print(count) | |
| return count |
No description provided.