No subject

Mark Kettner mark at
Sat Apr 20 02:39:27 EDT 2019

On 19 Apr 2019 at 16:37, Tamara Berger <brgrt2 at> wrote:
> What code can I use to break out of a program completely, and not just out
> of a loop?


... but this exits the python interpreter. inside a function, a return
statement might be more suitable.

> I wrote code with 3 conditions for saving for a downpayment. The
> first addresses cases that don't meet the minimum condition; i.e., enough
> money to save for a downpayment within the allotted time. It has its own
> print line, but also executes the irrelevant print lines for the other two
> conditions.

maybe you should regroup your if-statements. Or if you only want to
display error messages of the first condition a user didn't met, save
your conditions and the error messages as a tuple in a list and iterate
over it:

payment_ok = [
    (cond1, "Not enough money"),
    (cond2, "some other error"),
    (cond3, "even another error"),
all_ok = True
for cond, err_str in payment_ok:
    if not cond:
        all_ok = False

Mit freundlichen Gruessen / Best Regards

Mark Kettner

More information about the Python-list mailing list