I would like to charge a car under the condition that in the end it is charged at least 75% and if prices are positive I would like it to continue charging, but not surpass the maximum of 100%. The list of prices are the prices for everytime I charge (or decide not to charge) the car.
So here is what I have so far:
maxF = 100
minF = 75
SoC = 55
i = 0
chargeRate = 10
price = [2,-2,3,4]
while SoC < minF:
if price[i] > 0:
SoC += chargeRate
i += 1
# if there is no time left (no prices available), I have to charge in order to reach 75%
elif (minF - SoC)/chargeRate <= (len(price) - i):
SoC += chargeRate
i += 1
else:
i += 1
print(SoC)
In this piece of code the car charges prices 2 and 3, but not 4. I don't know how to include for the car to continue charging, after having passed the 75%.
I am greatful for any suggestions.
Many thanks, Elena
whileloop will stop ifSoC < minF, as you specified. what do you intend to do with the variableprices?i += 1in every possible condition of yourifstatement, you should simply have it once outside of theif