0

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')
Cardstdani
  • 4,999
  • 3
  • 12
  • 31
Arian
  • 57
  • 9

2 Answers2

2

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')
Cardstdani
  • 4,999
  • 3
  • 12
  • 31
1

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 0 in [istep, ito]:
       os.system('cls')
Dmitry
  • 123
  • 1
  • 8