PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Fibonacci

← All stacks

Theory

106/268

Fibonacci

Fibonacci is a classic practice problem. State the rule, trace a tiny input, then code. Fibonacci: next = sum of last two. Second largest: watch duplicates. Hanoi: move n-1, biggest, n-1. Distance: sqrt((x2-x1)**2 + (y2-y1)**2).

For Fibonacci — say the output for one small n before you write the loop. That is the exam.

Fibonacci — output — [0, 1, 1, 2, 3, 5]. Real sequence, not dummy numbers.

Exam tip

Rule + one dry-run + then code.

Example

# Fibonacci
a, b = 0, 1
out = []
for _ in range(6):
    out.append(a)
    a, b = b, a + b
print(out)

Fibonacci — output: [0, 1, 1, 2, 3, 5]. Real sequence, not dummy numbers.

Short notes

  • DefFibonacci — know the rule.
  • RuleFibonacci — tiny trace first.
  • RememberFibonacci — edge cases (n=0, duplicates).

Questions

1

Explain Fibonacci as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Fibonacci?

Previous← nsetoolsNextOpenCV detection →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.