Кто-нибудь может помочь с этим кодом? Я пишу этот код для вычисления некоторых значений по некоторым уравнениям. Я начал читать значения CSV в словарь, но после вычисления значений для достижения окончательного набора параметров я не могу найти способ многократно повторять один и тот же список.
Проще говоря, у меня есть два ввода перечисляет dPdT и listT. Мне нужно перебрать каждый параметр списка dPdT над listT и создать три разных списка P.
Благодарю всех, кто хочет помочь. Это учебный проект для курса.
# Request user's interval parameters for calculations
print("Inform the temperature range and interval (°C). Only integers.")
minT = int(input("Min: "))
maxT = int(input("Max: "))
stepT = int(input("Temperature interval: "))
# create a list of temperature values to compute pressure parameters
listT = []
for x in range(minT, (maxT+stepT), stepT):
listT.append(x)
# Open CSV file in read mode to acces data and read it into a dictionary
with open(CSVfile, "r") as CSV:
reader = csv.DictReader(CSV)
listDict = []
# Creates a list of dictionaries with the fluid inclusion parameters
for lines in reader:
listDict.append(lines)
# Define list parameters to be computated
a, b, c, dPdT, P = [], [], [], [], []
# Loop iterates over the dictionary list and computates parameters a,b,c stored in lists a,b,c
for i, rows in enumerate(listDict):
a.append(i)
b.append(i)
c.append(i)
if "sal" in rows:
a[i] = (18.28 + 1.4413 * float(rows["sal"]) + 0.0047241 * float(rows["sal"]) ** 2
+ 0.0024213 * float(rows["sal"]) ** 3 + 0.000038064 * float(rows["sal"]) ** 4)
b[i] = (0.019041 - 1.4268 * 0.01 * float(rows["sal"]) + 5.66012 * 0.0001 * float(rows["sal"]) ** 2
- 4.2329 * 0.000001 * float(rows["sal"]) ** 3 - 3.0354 * 0.00000001 * float(rows["sal"]) ** 4)
c[i] = (- 1.5988 * 0.0001 + 3.6892 * (10 ** -5) * float(rows["sal"]) - 1.9473 * (10 ** -6) * float(rows["sal"]) ** 2
+ 4.1674 * (10 ** -8) * float(rows["sal"]) ** 3 - 3.3008 * (10 ** -10) * float(rows["sal"]) ** 4)
# Loop iterates over the dictionary list and computates dPdT to store the values in list dPdT
for i, rows in enumerate(listDict):
dPdT.append(i)
if "th" in rows:
dPdT[i] = a[i] + b[i] * float(rows["th"]) + c[i] * float(rows["th"]) ** 2
# Loop populates list P (pressure values)
for i in range(len(listT)):
P.append(i)
# problem starts here: I need to iterate over the listT or P, repeating it for every dPdT values.
# Loop to calculate P based on lits dPdT and listT.
while i in range(len(dPdT)):
for j in range(len(P)):
P[j] = dPdT[j] * listT[j]