Home > Software design >  If statements running at the same time how to
If statements running at the same time how to

Time:01-05

if input("Raining? ") == "yes":
    print("Then you should take an umbrella")

if input("Raining? ") == "no":
    print("Then you should not take an umbrella ")

so I want these 2 to check yes or no at the same time so when I type no the printed answer should be "Then you should not take an umbrella" but the thing is it asks twice when I say no example:

Raining? no
Raining? no
Then you should not take an umbrella

any ideas how I can make this work ?

I just want to ask you Raining? no and the answer to be Then you should not take an umbrella, not asking you twice and the second time works

CodePudding user response:

Ask for the input before the if statement.

For example:

value = input("Raining? ")
if value == "yes":
    print("Then you should take an umbrella")
elif value == "no":
    print("Then you should not take an umbrella")

CodePudding user response:

Just save the input to be compared later.

inp = input("Raining? ")
if inp == "yes":
    print("Then you should take an umbrella")
elif inp == "no":
    print("Then you should not take an umbrella ")
  •  Tags:  
  • Related