Anonymous asked in Computers & InternetProgramming & Design · 1 month ago

How do I make my python program stop when before it hits less than one?

number = int(input('Enter a number: '))

count = 0

while True:

  if number > 1:

     number = number / 2

     count = count + 1

     print (f'{count}.) {number}')


  elif number <= 1:


 This is my code, but it prints out numbers less than one and I don't want it to do that. 

1 Answer

  • 1 month ago
    Favorite Answer

    The first statement in the loop divides number in half.  If you want that to only run when the halved number is 1 or more, then change the loop condition to:

         while number >= 2:

             number /= 2


    • Log in to reply to the answers
Still have questions? Get answers by asking now.