-
Notifications
You must be signed in to change notification settings - Fork 0
Create demoriyana #15
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
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,31 @@ | ||||||||||||||||||||||||||||||||||||||||
| def calculate_average(numbers): | ||||||||||||||||||||||||||||||||||||||||
| # Missing variable initialization | ||||||||||||||||||||||||||||||||||||||||
| total = sum(numbers) | ||||||||||||||||||||||||||||||||||||||||
| count = len(numbers) | ||||||||||||||||||||||||||||||||||||||||
| return total / count | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correctness: The 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def process_data(data): | ||||||||||||||||||||||||||||||||||||||||
| # Incorrect function call | ||||||||||||||||||||||||||||||||||||||||
| result = data.sort() # sort() returns None | ||||||||||||||||||||||||||||||||||||||||
| return result | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect use of sort() method. The def process_data(data):
- # Incorrect function call
- result = data.sort() # sort() returns None
- return result
+ # Option 1: Use sorted() to return a new sorted list
+ return sorted(data)
+
+ # Option 2: Sort in-place and return the modified list
+ # data.sort()
+ # return data📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correctness: The 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def main(): | ||||||||||||||||||||||||||||||||||||||||
| # Undefined variable | ||||||||||||||||||||||||||||||||||||||||
| numbers = [1, 2, 3, 4, 5] | ||||||||||||||||||||||||||||||||||||||||
| average = calculate_average(numbers) | ||||||||||||||||||||||||||||||||||||||||
| print(f"The average is: {average}") | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Type mismatch | ||||||||||||||||||||||||||||||||||||||||
| text = "Hello" | ||||||||||||||||||||||||||||||||||||||||
| number = 42 | ||||||||||||||||||||||||||||||||||||||||
| result = text + number # Can't concatenate string and integer | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix type mismatch in string concatenation. Python can't directly concatenate strings and integers. You need to convert the integer to a string first. # Type mismatch
text = "Hello"
number = 42
-result = text + number # Can't concatenate string and integer
+result = text + str(number) # Convert integer to string before concatenation📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correctness: Type error when attempting to concatenate a string and an integer with 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Incorrect list operation | ||||||||||||||||||||||||||||||||||||||||
| my_list = [1, 2, 3] | ||||||||||||||||||||||||||||||||||||||||
| my_list.append(4, 5) # append() takes only one argument | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect list append operation. The # Incorrect list operation
my_list = [1, 2, 3]
-my_list.append(4, 5) # append() takes only one argument
+# Option 1: Append items one at a time
+my_list.append(4)
+my_list.append(5)
+
+# Option 2: Use extend() to add multiple items at once
+# my_list.extend([4, 5])📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correctness: The 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Using undefined variable | ||||||||||||||||||||||||||||||||||||||||
| print(undefined_variable) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove or define the undefined variable. The code attempts to print a variable that hasn't been defined, which will cause a -# Using undefined variable
-print(undefined_variable)
+# Either define the variable first
+undefined_variable = "Now I'm defined"
+print(undefined_variable)
+
+# Or remove the print statement entirely if the variable isn't needed📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correctness: Reference to undefined variable 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||||||||||||||||||||
| main() | ||||||||||||||||||||||||||||||||||||||||
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.
🛠️ Refactor suggestion
Good implementation of average calculation but needs error handling.
The function correctly calculates the average by summing numbers and dividing by count. However, it lacks error handling for empty lists which would cause a division by zero error.
📝 Committable suggestion
🤖 Prompt for AI Agents