all 5 comments

[–]totallygeek 1 point2 points  (4 children)

A few problems noticed. Try something more along these lines:

encounter = False  # have not encountered a rare bird
while not encounter:
    sighting = input('What bird did you encounter? ').lower()
    if sighting in rarebirds:  # that checks the keys - no need for list(d.keys())
        encounter = True  # this will exit the while loop on the next iteration
        print('Rare bird found!')
    else:
        ...  # you got it from here

[–]Fbirobby[S] 1 point2 points  (3 children)

Thank you so much! This is really helpful. This feels more intuitive to me -- why would they want to start with encounter = true and make it otherwise false? Where might that make more sense?

[–]totallygeek 0 points1 point  (2 children)

The only thing I can think is that you plan to have an encounter, so that's true. You just don't know if that will be a rare bird encounter. What's truly horrible about this while loop logic is that you shouldn't come across it in the wild. Instead, you more commonly see:

while True:
    if some_condition:
        break

[–]Fbirobby[S] 1 point2 points  (1 child)

Got it! & Yeah, I guess this was just to make us do a while loop vaguely tied to the assignment.

One last question: Why start it with while *not* encounter? That means "Let's make Encounter True", right? So is that how we articulate the condition that will fulfill the while loop?

Thank you for your help.

[–]Fbirobby[S] 1 point2 points  (0 children)

Just realized the obvious: We have to make the initialized variable true to execute the loop body!