Read the question, write Python on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read n and print the integers from 1 to n that are not multiples of 3, space-separated.
continue is the tidy way to skip a loop body when a condition matches.
Input. One line: an integer n ≥ 1.
Output. Space-separated integers that are not multiples of 3.
Constraints
- 1 ≤ n ≤ 50
Examples
Input
10
Output
1 2 4 5 7 8 10
Hint
- if i % 3 == 0: continue
- A comprehension with if i % 3 != 0 also works.
Show correct code
Peek only after you have tried. You can still Check your own version.
n = int(input())
print(*[i for i in range(1, n + 1) if i % 3 != 0])
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.