dimanche 26 novembre 2017

Reading a list with multiple data types into "if else" statements

I currently have this function I am working on (below):

def ThermoControl(datas):

    Accepted_Price = 13

    for data in datas:
        if Price > Accepted_Price:
            ac_on = False    #Heater Off
        elif weather == "cloudy":
            ac_on = False
        else:
            ac_on = True #Heater On
    return ac_on

I want the function to iterate through a list with two data types (integer and string) like the one below:

data = [[10, "cloudy"], [12, "sunny"], [9, "sunny"]]

The positions in the brackets correlate to [Price, weather]

Is there a way to have the function iterate through the list ("data") by checking each value in the pair and then moving on to the next index in the list?

If the function were to work with the aforementioned list, I would expect this output:

[False, True, True]

Aucun commentaire:

Enregistrer un commentaire