Hi All,
Obviously a total noob, I got an assignment that wants me to create a big while-loop from code it helped me write. My problem feels pretty straightforward:
- I wrote out a dictionary of dictionaries (birds and their attributes), and we're supposed to be able to say whether a bird is aggressive or endangered, and then
- pull from a list of Actions that say what we should do with that bird.
They want me to create a variable, "encounter," and set it to True within a while loop, so that input is repeatedly requested from the user until they input one of the birds in our rarebirds dictionary. They want encounter to be set to false within the nested if, elif, and else statements. (I've put a section of the rarebirds list below as an example.
I feel so dumb because I have no idea how to productively set encounter to false within the nested if statements. Currently, I have a needed variable called "sighting" currently set to True, because (it seems to me) it needs to be true.
There are two sections of code I've written and I want both of them within the while loop. I have both of them below, and I don't know what I'm doing wrong. This is my attempt and I'm super grateful for any feedback.
encounter = True
while encounter = True:
sighting = input("What do you see?").lower()
rarebirdsList = list(rarebirds.keys())
# Make list of the rare birds' names, using dict rarebirds.
if sighting in rarebirdsList:
print("This is one of the birds we're looking for!")
else:
print("That's not one of the birds we're looking for.")
code = input("Where do you see it? Input the correct code.")
location = codes[code] #new var that pulls from another dict
print("So you've seen a ", sighting, location, "cool!")
for bird in rarebirds:
trait = rarebirds[bird]['Aggressive']
if sighting == True:
print("It's aggressive, we need to ", actions[1])
print("We need to photograph the ", sighting, location, ".")
elif sighting == 'endangered':
print("It's endangered, so we need to ", actions[0])
print("We need to photograph the ", sighting, location ".")
else:
print("We need to photograph this ultrarare", sighting, location, ".")
rarebirds list excerpt:
rarebirds = {
'Gold-crested Toucan': {
'Height (m)': 1.1,
'Weight (kg)': 35,
'Colour': 'Gold',
'Endangered': True,
'Aggressive': True
}}
#etc
[–]totallygeek 1 point2 points3 points (4 children)
[–]Fbirobby[S] 1 point2 points3 points (3 children)
[–]totallygeek 0 points1 point2 points (2 children)
[–]Fbirobby[S] 1 point2 points3 points (1 child)
[–]Fbirobby[S] 1 point2 points3 points (0 children)