If condition in while loop in Python
In the while
loop, you can also use the if
condition and the break
statement.
Let's divide the number 10.5
by 2
until the result is less than one:
num = 10.5
while True:
num = num / 2
if num < 1:
break
print(num) # 0.65625
You are given a number. Divide it by 2
as many times as necessary until the result is less than 10
. What number do you get?
Given an integer, get a list of divisors of this number.