← Back to challenges

The Red/Yellow Sequence

PythonHardalgebramathnumbers

Instructions

Write a function that takes a number n and a string s as arguments and returns the nth term of the Red/Yellow sequence. s will ask the function what to return, all, red or yellow.

alt text

Examples

ry_seq(2, "all") ➞ 5

ry_seq(3, "yellow") ➞ 8

ry_seq(28, "red") ➞ 55

ry_seq(1, "blue") ➞ False

Notes

  • If s is not "all", "yellow" or "red", return False.
  • If n is 0, return 0.
  • n is always a positive integer.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.