#Do iIuse if or elif????
33 messages · Page 1 of 1 (latest)
delivery = input("Would you like this delivered? - ")
if delivery == "N" or "No":
if delivery == "Y" or "Yes":
input("Please type your address!: ")
Yeah, you'd unindent the second if statement to be at the same level as the first one, and make it into an elif
!exec
delivery = input("Would you like this delivered? - ")
if delivery == "N" or "No":
if delivery == "Y" or "Yes":
address = input("Please type your address!: ")
print(address)
N
Y
Something
@red osprey
Would you like this delivered? - N
Please type your address!: Y
Y
ahh got it thanks!
Oh
And
if delivery == "N" or "No": extended is this:
if delivery == "N" or "No" != None:
So, basically it's these two statements:
if delivery == "N":
if "No" != None:
Ohh okay
>>> "No" != None
True
So having just "No" or "Yes" after the or means those statements will always run
The syntax is if statement1 OR statement2:
"No" string will never be None, so it'll always run
alrighty
You could also use if delivery in list: for the statements if you don't want to make long lines
And set the list to be a list containing "N", "No"
Or "Y", "Yes"
Okok
while True:
if delivery == "Y":
address = input("Please type your address!: ")
break
For this one, is it the same?
Because when I tried running it and entering "Y", it repeats its self
that is because "delivery" didn't = "Y" which is why it kept reiterating the loop
delivery has to = "Y" for the user to be asked to input a address