'Looping problem Elden ring runes per level calculation
This code is currently showing the total amount needed to reach the next level, but what I would like it to do is show the complete total amount so for example if you pick 50 the total amount needed from level 1 to 50. Looping through the calculation from 50 to 1 and only showing the sum of that total. and hereby I mean only showing the total amount of runes needed to reach level 50 for example, but I seem to get the entire list for each level. I, unfortunately, can't seem to find the right way to do this online, so I would try my luck here. any help is appreciated.
def total_runes_per_lvl(lvl):
list = []
for i in range(lvl):
runes = 0.02*(lvl)**3 + 3.06*(lvl)**2 + 105.6*(lvl) - 895
list.append(runes)
lvl -= 1
print(sum(list))
total_runes_per_lvl(50)
15102.68
14535.0
28514.440000000002
41950.32
54854.520000000004
67238.8
etc`
should only be one number: 277.571
Solution 1:[1]
Your identation is incorrect, and you're decrementing lvl
even though there's already an iterator on it.
def total_runes_per_lvl(lvl):
total = 9381
for i in range(13,lvl+1):
runes = 0.02*(i+1)**3 + 3.06*(i+1)**2 + 105.6*(i+1) - 895
total += int(runes)
print(total)
total_runes_per_lvl(16) # 15605
total_runes_per_lvl(50) # 277574
Edit: since the formula works accurately after level 12, I've hardcoded the value for the total of first 12 levels. The formula works as expected, though it still isn't accurate.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |