简体   繁体   中英

Multiple conditions in Python

I am trying to get a Python code running that shows the first year that certain conditions are met. This has to be done in two steps. I am unable to see what I am doing wrong.

The program is loading a CSV file in. I have created two lists

for a in reader:            
        temperature = [int(a['TX'])]
        day = [int(a['DATE'])]

The next step is an iteration over range of a length of temperature:

for x in range(len(temperature)):

The next step is a while-loop:

while temperature[x]>= 250 and temperature[x+1] >= 250

The following I am doing is:

            temp_temperature = [temperature[x]]
            temp_day = [x]

The logic behind would be that all temperatures that meet the while loop are saved in the list along with the index of the temperature.

The temperature has to meet the condition that it is five consecutive days above 25 degrees. If it has met this condition, it it has to verify that the temperature is above 30 degrees for three consecutive days. If this is the case, it has to print the first occurrence of both conditions.

In-case a condition is not met:

            i += 0
            temp_day.clear()
            temp_temperature.clear()

Thank you in advance for helping me out!

I have been able to solve the issue with your help! The issue was that I had to use a initialize the list first and append it afterwards. So this resulted in:

tempature = []
day = []

for a in reader:            
        temperature.append(int(a['TX']))
        day.append(int(a['DATE']))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM