Kodewick
Start learning →
Basic←→0 / 80

Lift keypad

#053BasicErrorsConditions5 min

This building has floors 1 to 12, and the lift has a keypad you can type on. Write pick_floor(text): if the text is a number from 1 to 12, return that int; if it isn't a number, or there is no such floor, return None. The floor check is already in the starter.

Examples
pick_floor("5")→5
pick_floor("lobby")→None
pick_floor("15")→None
main.py
def pick_floor(text):
    floor = None
    # your code here: try to turn text into an int in floor; on ValueError leave floor as None
    if floor is None or floor < 1 or floor > 12:
        return None
    return floor
Ctrl + Enter runs too
Result

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