5.1. Exercises
Conditional Loop Questions
parking_lot = [ 20, 60, -12, 110, -20, 80, 12, -40, 37, 92]
parking_tickets = list()
for stall in parking_lot:
if stall <0:
parking_tickets.append(True)
else:
parking_tickets.append(False)
sum(parking_tickets)parking_lot = [ 20, 60, -12, 110, -20, 80, 12, -40, 37, 92]
parking_tickets = []
for stall in parking_lot:
if stall <0:
break
else:
parking_tickets.append(False)
sum(parking_tickets)Practice Iterating Over a Collection
Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.
When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.
Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.
For the last few Modules, we have been playing with different dataframes. In this question, we have stored them in a list named dataframes.
Let’s count how many of these dataframes have more than 1000 rows.
Tasks:
- Make an object named
countand assign it a value of 0. - Loop through the dataframes and count how many of them have more than 1000 rows.
- Hint: you can use
.shape[0]to access the number of rows in a dataframe. countshould increase by 1 if the dataframe has more than 1000 rows and 0 otherwise.- Display the value of
count.