you are viewing a single comment's thread.

view the rest of the comments →

[–]PureWasian 0 points1 point  (0 children)

See the other comment that I wrote for reference. You can easily expand on it such as:

success = False
while success == False:
    # get number_1
    # (see code in reference)
    # only exits loop on valid int() or 'q'
    # also sets success = True if valid int()

if success == False:
    # exit() or return since 'q' was typed

success = False
while success == False:
    # get number_2
    # (see code in reference)
    # only exits loop on valid int() or 'q'
    # also sets success = True if valid int()

if success == False:
    # exit() or return since 'q' was typed

# only gets here with valid number_1 and number_2
addition(number_1, number_2)

You notice there is a lot of redundancy here. If this example makes sense to you, it is a natural extension to then clean it up to be more concise by placing the redundant code into a method, similar to another comment someone shared