Chapters
Python114 chapters

Exercises

Break and Continue

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Print the first name starting with G, then stop looking.

Python
names = ["Ada", "Grace", "Georgia"]
# print only the first G name
Exercise 2

Skip the blank rows and the comment rows, and print the rest split on the comma.

Python
rows = ["", "ada,36", "# a comment", "grace,45"]
for row in rows:
    # skip what you do not want, then print
    pass
Exercise 3

Find the target in the grid and return its row and column, or None. break alone cannot leave both loops.

Python
def find(grid, target):
    # return (row, col) or None
    pass

print(find([[1, 2], [3, 4]], 4))
print(find([[1, 2], [3, 4]], 9))