Home > Software design >  Clearing the console in python
Clearing the console in python

Time:06-26

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')

CodePudding user response:

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')

CodePudding user response:

simplier solution to use a list of values for if-statement

import os

while True:
   ifrom=int(input("From: "))
   istep=int(input("Step: "))
   ito=int(input("To: "))
   if False in [istep, ito]:
       os.system('cls')
  • Related