Challenge 2: Count Iterations of a Loop Until a Condition
This challenge will test your knowledge of while loops.
We'll cover the following
Problem Statement
-
A variable
x
is provided to you. -
Repeatedly decrease the value of the variable
x
by 3 each time, as long asx
is greater than or equal to 0. -
Print the number of times the iteration runs.
Input
integer
Output
iteration count
Sample Input
21
Sample Ouput
8
Coding Exercise
Write your code below. It is recommended​ that you try solving the exercise yourself before viewing the solution.
Note: There is a
test
function given in the code for testing purposes. Do not modify it.
Important Note: A mutable variable
x
is already provided to you. This has the desired value. You just have to write thewhile
loop construct.
Good luck! 🤞
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy