-
Notifications
You must be signed in to change notification settings - Fork 0
Update main.py #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?
Update main.py #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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ def nth_fibonacci_util(n, memo): | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Base case: if n is 0 or 1, return n | ||||||||||||||||||||||||
| if n <= 1: | ||||||||||||||||||||||||
| return n | ||||||||||||||||||||||||
| return m | ||||||||||||||||||||||||
|
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. 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. Variable Name ErrorThe variable 'm' is undefined in this context. This will cause a NameError when the function is called with n <= 1, completely breaking the Fibonacci calculation functionality.
Suggested change
Standards
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. Undefined Variable ReferenceThe function attempts to return variable 'm' which is undefined. This will cause a NameError when the function is called, breaking the Fibonacci calculation completely.
Suggested change
Standards
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. Variable Name Error in Fibonacci Base CaseThe variable 'm' is undefined in this context. This will cause a NameError when the function is called with n <= 1, breaking the Fibonacci calculation completely.
Suggested change
Standards
Comment on lines
20
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. Undefined Variable Reference in Fibonacci Base CaseThe code attempts to return an undefined variable 'm' in the Fibonacci base case. This will cause a NameError exception whenever the function is called with n <= 1, completely breaking the algorithm's functionality.
Suggested change
Standards
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Comment on lines
19
to
22
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 undefined name in base case (NameError) and validate input. Returning Apply this diff: - # Base case: if n is 0 or 1, return n
- if n <= 1:
- return m
+ # Base case: handle invalid input first, then trivial cases
+ if n < 0:
+ raise ValueError("n must be non-negative")
+ if n <= 1:
+ return n📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.12.2)21-21: Undefined name (F821) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| # Check if the result is already in the memo table | ||||||||||||||||||||||||
| if memo[n] != -1: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
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.
Variable Name Error
The variable 'm' is undefined in this scope. This will cause a NameError when the function is called with n <= 1, breaking the Fibonacci calculation entirely.
Standards