如何在dict中调用下一个值?
i used the dict
LEVEL_XP = {
0: 0,
1: 5,
2: 13,
3: 20
}
and the code
new_level = int(level)
for level_on, xp_needed in LEVEL_XP.items():
i = LEVEL_XP[xp_needed]
if 0 <= i:
if xp != i:
print('nothing')
break
else:
new_level = int(level_on) + 1
print('level up')
break
else:
new_level = int(level)
break
where i could call level
and xp
from database and it works fine. the problem is after i reach 13
xp, i dont level up to 2
and its printing nothing
. i've found the reason that the xp_needed
calls only 0
which is the first value in the dict. 如何获得代码考虑下一个值,该值是13
在我级别1
时? 以及如果我喜欢将整个XP删除至0并使用级别1
重新启动,则该怎么办,因此代码需要调用13
为xp_needed
接下来,不是5
?
i used the dict
LEVEL_XP = {
0: 0,
1: 5,
2: 13,
3: 20
}
and the code
new_level = int(level)
for level_on, xp_needed in LEVEL_XP.items():
i = LEVEL_XP[xp_needed]
if 0 <= i:
if xp != i:
print('nothing')
break
else:
new_level = int(level_on) + 1
print('level up')
break
else:
new_level = int(level)
break
where i could call level
and xp
from database and it works fine.
the problem is after i reach 13
xp, i dont level up to 2
and its printing nothing
.
i've found the reason that the xp_needed
calls only 0
which is the first value in the dict.
How can i get the code consider next value which is 13
in the dict when i am level 1
?
and How to do if i like erase the whole xp to 0 and restart it with level 1
, so the code need to call 13
as xp_needed
next, not 5
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在下面使用循环时使用
。
It takes advantage of experience being monotonic with level.
We can probe each
[level + 1]
element quite efficiently,without having to visit the "tons" of levels you mentioned.
We only examine levels that could be relevant.
Use the
while
loop below.It takes advantage of experience being monotonic with level.
We can probe each
[level + 1]
element quite efficiently,without having to visit the "tons" of levels you mentioned.
We only examine levels that could be relevant.