The question is probably stupid, but I can't catch the error in my thoughts. I need to find the least common multiple. I know algorithms for solving this problem, but I wanted to experiment:
a = int(input())
b = int(input())
if a > b:
i = a
while i % a != 0 and i % b != 0 and i < a * b:
i += 1
print(i)
else:
i = b
while i % a != 0 and i % b != 0 and i < a * b:
i += 1
print(i)
However, the numbers I enter do not go through the while loop, i is output as I assigned it.
Help, please, to understand where I am stupid.
source https://stackoverflow.com/questions/74923498/why-is-the-while-loop-not-working-python
Comments
Post a Comment