Search code examples
pythonpython-3.xconsole

Clearing the console in python


I want to clear console by entering '0' in the 'istep' or 'ito' but in only works when I enter '0' in the 'ito'...can somebody fix this and explain what is the reason of this behavior?THANKS!

import os

while True:
   ifrom=int(input("From: "))
   istep=int(input("Step: "))
   ito=int(input("To: "))

   if istep==0 or ito==0:
       os.system('cls')

Solution

  • You need to use several if conditions, as ito only gets a value after user inputs something for istep:

    import os
    
    while True:
       ifrom=int(input("From: "))
       istep=int(input("Step: "))
       if istep==0:
           os.system('cls')
       ito=int(input("To: "))
    
       if ito==0:
           os.system('cls')