I've just started learning python recently because of work, and I'm struggling with a for loop in my code. I want my program to output values for amount of ammonia produced hourly, which is dependent on the cells in Excel (attached below), and I need the columns for 'H2 consumed by NH3' and 'Actual Stored' as lists in Python in order to move forward. However, when I run this code, the process is constantly running and doesn't stop, which made me realize I've messed up somewhere but I can't tell where.
hourly_H2_prod = [hourly_elec*1000/avg_pwr_use for hourly_elec in elec_list]
H2_sum = sum(hourly_H2_prod)
avg_hourly_H2_consumed = avg_hourly_NH3_prod*3/17.31
init_H2_stored = H2_sum/365*Storage_days #highlighted cell in Excel screenshot
actual_H2_stored = [init_H2_stored]
hourly_H2_consumed = []
for i in range(1,len(hourly_H2_prod)):
for j in range(len(actual_H2_stored)):
hourly_H2_consumed.append(max(min(avg_hourly_H2_consumed,actual_H2_stored[j]),0))
actual_H2_stored.append(max(min(init_H2_stored,actual_H2_stored[j]+hourly_H2_prod[i]-hourly_H2_consumed[j]),0))
I have already managed to get the list format for the 'hourly H2 production' column
(this is to show how the values are dependent on each other, for actual-H2-stored)
(how values depend for hourly-H2-consumed)
I think I'm messing up when I need to iterate using the previous variable as shown in the excel formula. I also hope I've explained everything fully, I appreciate any help!
for i in range(1,len(X))dofor ii,value in enumerate(X)it's more pythonic.