← Quiz: 1D Dynamic Programming Patterns: all 10 questions
Quiz: 1D Dynamic Programming Patterns · Question 2 of 10
What does this print? (code)
What does this print?
def ways(n):
a, b = 1, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b
print(ways(6))
- A.8
- B.21
- C.13
- D.6
Answer & explanation
Correct answer: 13
The sequence for n = 1..6 is 1, 2, 3, 5, 8, 13.
Can you get the rest right without peeking?
Take the timed Quiz: 1D Dynamic Programming Patterns quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →