mardi 9 avril 2019

Is there a way to count how many true/false outputs in a Boolean function with a for loop?

I have a Boolean function that looks like this:

def should_I_buy(data, input_price, input_day):
    """Returns whether one should buy flight ticket now or wait longer to buy"""
    for day, price in data:
        if day < input_day:
            if price < input_price:
                return False
    return True

The function works:

should_I_buy(data, 50.00, 8)
False

However, I also want to find a way to count how many True and Falses there are in the loop when I put in a random input_price and input_day, not just the sole output of either True or False.

Aucun commentaire:

Enregistrer un commentaire