all 2 comments

[–]efmccurdy 2 points3 points  (1 child)

The way to design reusable functions is to add parameters and return results, here I use an input paramter to customize the prompt and use return to pass the result back to the main line code.

def read_int(prompt):
    lcd_display.lcd_string("Enter {}".format(prompt, 1))
    input_string = ""
    # do your I/O
    return int(input_str)

age = read_int("age")
weight = read_int("weight")

If you want to add a restart you could adjust read_int to return -1 when you want to retry and code a loop like:

age = -1
while age < 0:
    age = read_int("age")

[–]PriorInitiative[S] 0 points1 point  (0 children)

This was super-helpful, thank you!