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')
2
  • Are you on Linux or WIndows? Commented Jun 25, 2022 at 11:38
  • @Cardstdani Hey, I'm using 'Windows 10' Commented Jun 25, 2022 at 11:38

2 Answers 2

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')
Sign up to request clarification or add additional context in comments.

1 Comment

the OP was already using the == on both conditions
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')

1 Comment

This is very inintuitive, doesn't if 0 in [istep, ito] make more sense?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.