x = 3
# The loop body will execute three times.  Once when x == 3, once when x == 4, and once when x == 5.
# Then x < 6 will evaluate to False, and it will stop.
# 3, 4, and 5 will be printed out.
while x < 6:
    print(x)
    # Using += is a shorter way of saying x = x + 1.  It will add one to x.
    x += 1

b = 10

"""
Explanation: 2: Writing a while loop
Instructions
Create a while loop that tests if b is greater than 5. If it is, the loop body should print b out, then subtract one from it.
End of explanation
"""


while b > 5:
    print(b)
    b -= 1

"""
Explanation: Answer
End of explanation
"""


available_count = 0
desired_dog = "Great Dane"
available_dogs = ["Labrador", "Poodle", "Sheepdog", "Great Dane", "Pomeranian", "Great Dane", "Collie"]

# Let's say we are searching for two dogs of the same breed to adopt.
# We'll loop through the dogs.
for dog in available_dogs:
    # If our desired dog is found.
    if dog == desired_dog:
        # Increment the counter.
        available_count += 1
        # We only want two dogs, so we can stop searching after we find them.
        if available_count == 2:
            break

tiger_count = 0
desired_tiger = "Bengal"
available_tigers = ["Bengal", "Dressed up poodle", "Siberian", "Sumatran", "Bengal", "Housecat", "Hobbes"]

"""
Explanation: 3: Using the break keyword
Instructions
Let's say we want two "Bengal" tigers from available_tigers for our nature reserve.
Write a for loop that increments tiger_count when it finds one, and breaks after finding two.
End of explanation
"""


for t in available_tigers:
    if t == "Bengal":
        tiger_count += 1
    if tiger_count == 2:
        break

"""
Explanation: Answer
End of explanation
"""


column_names = ['year',
 'month',
 'carrier',
 'carrier_name',
 'airport',
 'airport_name',
 'arr_flights',
 'arr_del15',
 'carrier_ct',
 'weather_ct',
 'nas_ct',
 'security_ct',
 'late_aircraft_ct',
 'arr_cancelled',
 'arr_diverted',
 'arr_delay',
 'carrier_delay',
 'weather_delay',
 'nas_delay',
 'security_delay',
 'late_aircraft_delay']

# It's pretty easy to get a column name from a column number.
# The third column contains the carrier (same as the airline).
print(column_names[2])

"""
Explanation: 4: Finding a column number from a name
Instructions
Write a function that will get the column number from the column name.
Use it to get the column number for the "arr_delay" column and assign it to the arr_delay variable.
Use it to get the column number for the "weather_delay" column and assign it to the weather_delay variable.
End of explanation
"""


def number_by_name(name):
    found = None
    for i, nm in enumerate(column_names):
        if nm == name:
            found = i
            break
    return found
            

arr_delay = number_by_name("arr_delay")
weather_delay = number_by_name("weather_delay")
print(arr_delay, weather_delay)

"""
Explanation: Answer
End of explanation
"""


from flight_delays import flight_delays
# Prints the last row in flight_delays
print(flight_delays[-1])

# Prints the second to last row in flight_delays
print(flight_delays[-2])

# Prints the third to last and second to last rows in flight_delays (remember that slicing only goes up to but not including the second number)
# This will get the rows at index -3 and -2
print(flight_delays[-3:-1])

"""
Explanation: 5: Using negative indexing
Instructions
Use negative indexing to assign the third to last row in flight_delays to third_to_last.
Use negative slicing to assign the fourth, third, and second to last rows in flight_delays to end_slice
End of explanation
"""


third_to_last = flight_delays[-3]
end_slice = flight_delays[-4:-1]

print(third_to_last, end_slice)

"""
Explanation: Answer
End of explanation
"""


