Daniel IG
Daniel IG

Reputation: 41

Python why i get tuple and how to avoid it

I dont know why but i get tuple when i calculate AIQhum in this case hum is >42 and i got this tuple (0, 190669.42) dont know why i get the 0 in the first place. How can avoid it forcing to not getting tuple just the second value? Thank you.

   def getCO2(self):
    try:
        hum = sensor.data.humidity
        gas=0
        for x in range(10):
            gas= gas+sensor.data.gas_resistance

        gasAvr=gas/10

        if hum < 38:
            AIQhum = -0, 625 * hum + 25

        if hum >= 38 and hum <= 42:
            AIQhum = 0

        if hum > 42:
            AIQhum = 0,4167 * hum - 16.667
        #time.sleep(30)
        print(gasAvr)
        if gasAvr > 50000:
            gasAvr = 50000
        if gasAvr < 5000:
            gasAvr = 5000
        IAQresistencia=-0.0017*gasAvr+83.33

        IAQglobal=AIQhum+IAQresistencia



        IAQ2=IAQglobal*5

        if IAQ2<=50:
            message="Good"
        if IAQ2>=51 and IAQ2<=100:
            message="Moderate"
        if IAQ2>=101 and IAQ2<=150:
            message="Unhealghy for sensitive groups"
        if IAQ2>=151 and IAQ2<=200:
            message="Unhealthy"
        if IAQ2>=201 and IAQ2<=300:
            message="Very Unhealthy"
        if IAQ2>=301 and IAQ2<=500:
            message="Hazarous"

Upvotes: 0

Views: 72

Answers (2)

Daniel IG
Daniel IG

Reputation: 41

The problem was the ",". I changed it to "." and it's working now.

Upvotes: 0

Jiř&#237; Baum
Jiř&#237; Baum

Reputation: 6930

In a couple of places you use a comma in place of a decimal point, eg 0,4167 instead of 0.4167

The 0,4167 is interpreted as a tuple (0, 4167) or even (0, 4167 * hum - 16, 667)

You need to use . for decimal point, like: (0.4167 * hum - 16.667)

Upvotes: 4

Related Questions