#Do iIuse if or elif????

33 messages · Page 1 of 1 (latest)

errant crest
#

delivery = input("Would you like this delivered? - ")
if delivery == "N" or "No":
if delivery == "Y" or "Yes":
input("Please type your address!: ")

(Im trying to make it so, if they type "Y", the code asks for its address, but if it chooses "N" it breaks and moves on. Kind of confused here XD

red osprey
#

Could you use a codeblock so the indentation shows up as well?

#

!formatting

topaz talonBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```py
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB

errant crest
#
delivery = input("Would you like this delivered? - ")
if delivery == "N" or "No":
  if delivery == "Y" or "Yes":
    input("Please type your address!: ")
red osprey
#

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

topaz talonBOT
errant crest
#

ahh got it thanks!

red osprey
#

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:

errant crest
#

Ohh okay

red osprey
#

You'd use if delivery == "N" or delivery == "No":

#

!eval "No" != None

topaz talonBOT
red osprey
#

So having just "No" or "Yes" after the or means those statements will always run

errant crest
#

OH OHOH

#

Now i get it

red osprey
#

The syntax is if statement1 OR statement2:

#

"No" string will never be None, so it'll always run

errant crest
#

alrighty

red osprey
#

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"

errant crest
#

Okok

errant crest
#
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

weak siren
#

delivery has to = "Y" for the user to be asked to input a address