-
Notifications
You must be signed in to change notification settings - Fork 27
I tried really #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
I tried really #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "python.testing.unittestArgs": [ | ||
| "-v", | ||
| "-s", | ||
| ".", | ||
| "-p", | ||
| "*test*.py" | ||
| ], | ||
| "python.testing.pytestEnabled": false, | ||
| "python.testing.unittestEnabled": true | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Learning Outcome: Functions""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import math | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import statistics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def sum_of_squares(n: int): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Calculate the sum of the squares of all integers from 1 to n. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -12,8 +13,13 @@ def sum_of_squares(n: int): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ValueError: If n is a negative integer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sumnum = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in range(1, n +1): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i = pow(i,2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sumnum.append(i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (sum(sumnum)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # sum_of_squares(5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def evaluate_performance(grades: list, min_pass: int): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Evaluate the performance based on a list of grades and a minimum passing grade. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -25,7 +31,13 @@ def evaluate_performance(grades: list, min_pass: int): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| str: "Pass" if the average grade is greater than or equal to min_pass, otherwise "Fail". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dict = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in grades: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if i >= min_pass: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{i} Pass" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{i} Fail" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # print(evaluate_performance([100, 70, 90, 75, 65], 75)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def calculate_cumulative_performance(scores: dict): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -37,7 +49,11 @@ def calculate_cumulative_performance(scores: dict): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dict: A dictionary containing the average score and a list of subjects where the score is below average. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lis = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in scores.values(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lis.append(i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return sum(lis)/len(lis) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+52
to
+55
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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} |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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} |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function prints the count but doesn't return it. According to the docstring, the function should return an int. Change print(count) to return count.
| print(count) | |
| return count |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function prints the sum but doesn't return it. According to the docstring, the function should return an int. Change print(sum(lis)) to return sum(lis).
| print(sum(lis)) | |
| return sum(lis) |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function prints the sum but doesn't return it. According to the docstring, the function should return an int. Change print(sum(lis)) to return sum(lis).
| print(sum(lis)) | |
| return sum(lis) |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function prints the list but doesn't return it. According to the docstring, the function should return a list. Change print(lis) to return lis.
| print(lis) | |
| return lis |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statistics module doesn't have an average() function. Use statistics.mean(nums) instead. Also, the function should return a tuple of (sum_list, average) as specified in the docstring.
| average = statistics.average() | |
| average = statistics.mean(nums) | |
| return (sum_list, average) |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function prints the dictionary but doesn't return it. According to the docstring, the function should return a dict. Change print(lis) to return lis.
| print(lis) | |
| return lis |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.