4/19


#1

How do I pass this, it keeps asking for me to repeat my answer.
When I include "break" - just to end it after - it says it's not in a loop.

choice = raw_input('Enjoying the course? (y/n)')

while choice != "y" or "n":  # Fill in the condition (before the colon)
    choice = raw_input("Sorry, I didn't catch that. Enter again: ")

#2

This one works

choice = raw_input('Enjoying the course? (y/n)')

while choice != "y" and choice != "n": # Fill in the condition (before the colon)
choice = raw_input("Sorry, I didn't catch that. Enter again: ")


#3

but it should be or
beacause if it is and it will be true if both the conditions is true, but every time one of the conditions will be false as choice can contain only y or n at any particular time so, it shoould always be false.


#4

Because we have the conditions being compared with a not equal to. If we put an or, what would happen is that it would always read as true, because choice will always be true because it cannot be equal to y and n. If it was equal to y and n, it would come out as false or false, but because it cannot be equal to two different things it will come out as true or false, or false or true. with an and statement, it will break the loop because the and statement must have both parts be true, while the or needs only one part to be true.


#5

sincere thanks bro keep helping like this! :smile:


#6

What threw me was the hint shows A and B but when you read the instructions it states choice does not equal A and choice does not equal b


#7

I agree ... I still don't get it why it's an 'and' here.
A mistake ?


#8

@chipblaster88596

Your original code is really close to what would be perfect for this problem. Though i personally would not use the != comparative for this and instead would use a not in statement. such as follows.

Though there is no fault with what you did vs. what the instructions ask. It is bad form on this particular section of the course.

EXAMPLE:

choice = raw_input('Enjoying the course? (y/n)')

while choice[0] not in ('y' or 'n'):
    choice = raw_input("Sorry, I didn't catch that. Enter again: ")

#9

Hi, I tried that your code, but, it works only when in 'y' condition.

Not works at all in case of 'n'

I don't have any idea why, but, it doesn't - it seems very clearly logically understandable what your point.

I was wondering if it would be successful, when you inputted the 'n'


#10

Probably, It would be easier to think it this way,

Choice is Not equal 'y' or Choice is Not equal 'n'
In logical way => Choice != 'y' or Choice !='n'
In short => Choice != ('y' and 'n')

You know, Not(A and B) = Not A or Not B
Not(A or B) = Not A and Not B


#11

@cutbamaster

That was my bad on that part I put it in backwards, the order does matter in this case. Check the code again.


#12

It works when "Not A and Not B"

but,

It doesn't works when "Not(A or B)"

why? anyone know? it's kinda python rule?


#13

@cutbamaster

You have to use it like this, the reason is because if you use just not it will only look at the next argument. The in augments the not and tells it that we are looking at the next list/dict what ever object we pass.

Does that make sense?

x = [1, 2, 5]
if 3 not in (x or 3):
    print(True)

#14

This code works. Your over thinking it. It only wants a legit answer. Do you like the course yes or no. anything other than a yes or a no results in a repeat of the question. the code here works.

choice = raw_input('Enjoying the course? (y/n)')

while choice != 'y' and choice != 'n': # Fill in the condition (before the colon)
choice = raw_input("Sorry, I didn't catch that. Enter again: ")


#15

when I enter anything else than y or n, it shows me this:


#16

Did you read your error message? Then did you look at your code for what it is talking about?

I can see it right now because I happened to read the error message.


#17

oh damn, choiSe! I think I should improve my writing skills in Englsih :smile:


#18

No worries, I have a thing where some of my fingers move faster than the rest so I always end up typing things like teh instead of the. You just have to become more proficient at finding your mistakes.


#19

I'm still confused what's the answer


#20

The answer is this:

`choice = raw_input('Enjoying the course? (y/n)')

while choice != "n" and choice != "y":  # Fill in the condition (before the colon)
    choice = raw_input("Sorry, I didn't catch that. Enter again: ")`

A while loop would execute when the condition is true. :slight_smile: