Kodewick
Start learning →
Basic←→0 / 80

Watch heart rate

#051BasicErrorsLists5 min

A running watch logs your heart rate every minute as text, and now and then a reading breaks and comes out as something like "--". Write heart_rates(readings) to turn every reading that can be a whole number into one and return them in order, skipping the broken ones.

Examples
heart_rates(["72", "--", "75"])→[72, 75]
heart_rates([])→[]
main.py
def heart_rates(readings):
    good = []
    for text in readings:
        # your code here: try to turn text into an int and add it to good; skip it on ValueError
        pass
    return good
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.