Ask coding questions

← Back to all posts
Rocket Launch Sequence
Charlie406 (1)

I am making a launch sequence and am trying to specify that if launch (domain) doesn't equal 1 or 2 then ask it to re enter 1 or 2 but I can't figure out how to get the while loop to identify 1 and 2 are both valid I would appreciate some help or just feel free to test it out, Thank you :).

Comments
hotnewtop
Coder100 (18071)

Maybe or?

if a == 1 or a == b:

make sure to don't fall into the trap of:

if a == 1 or b:

or else you get:

if a == True # 1 or b gets evaluated first
Charlie406 (1)

@Coder100 I honestly did not know or existed lmao but won't that shut off the program if you type something other than 1 or 2?

poetaetoes (315)
if (input) == 1:
   (code here)
elif (input) ==2:
    (code here)
else:
(input statement)
Charlie406 (1)

@poetaetoes yes I tried that but if you do it that way won't the program shut off when you don't input 1 or 2?, I want it to let them enter the number again until they enter a 1 or 2 hence the while loop maybe I'm wrong though idk

poetaetoes (315)

@Charlie406
oh so put a function.

def(loop):
   if (input) == 1:
      (code here)
   elif (input) ==2:
     (code here)
   else:
    loop()
loop()
poetaetoes (315)

@Charlie406 also, i can help you shorten the code.

poetaetoes (315)

@Charlie406

print("---------------------------------------------------------\n Com1: 
Com2 this is Com1, Button has been pressed, Over...")
  
poetaetoes (315)

@poetaetoes do that for all the ------ and the text

Charlie406 (1)

@poetaetoes I would but I'm planning on changing the text colour and having them separate is easier for me to handle being as I'm beginner and I'm not on def functions and stuff just yet sorry