Exercise: Number Sequence
Let's use conditionals to generate the correct number in a sequence!
We'll cover the following
Problem Statement
Given an integer, n
, between 0
and 9
, generate the n+1
number.
You can use your preferred conditional to solve this problem.
Sample Input
n = 3
Sample Output
4
Coding Challenge
Take some time to figure out all the possible cases for the values of n
. Keep in mind that n
can go up to 9
, which means the last number in the whole sequence will be 10
.
For any value of n
outside the specified range, just return -1
.
If you feel stuck, you can always check out the solution review in the next lesson.
Good luck!
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy