Answer the question
In order to leave comments, you need to log in
What is the best way to calculate the level based on experience?
I need to make a level determination based on experience points, but nothing better than this comes to my mind:
def lvl(points: int):
if points <= 2:
return 0
if points <= 5:
return 1
if points <= 15:
return 2
Answer the question
In order to leave comments, you need to log in
<?php
global $post;
$postslist = get_posts( array( 'posts_per_page' => 2, 'category'=>'news' ) );
foreach ( $postslist as $post ){
setup_postdata($post);
?>
<div>
<?php the_date(); ?> - выводит дату новости
<?php the_title(); ?> - выводит заголовок новости
<?php the_excerpt(); ?> - выводит краткое описание
<?php the_post_thumbnail(); ?> - выводит превью новости - картинку
</div>
<?php
}
wp_reset_postdata(); ?>
Either the option above, or use the function https://codex.wordpress.org/Plugin_API/Action_Refe... to change the cycle on the main (well, internal if necessary).
And working with the usual cycle.
You can implement like this:
RANKS = {
0: 2,
1: 5,
2: 15,
}
def get_rank(points: int) -> int:
for k, v in RANKS.items():
if points <= v:
return k
You can create a regular dictionary, in which the level is the key, and the amount of experience is the value
levels = {0: 2, 1: 5, 2: 15}
def get_level(current_xp):
sorted_levels = dict(sorted(levels.items()))
for level, xp in sorted_levels.items():
if current_xp <= xp:
return level
else:
return list(sorted_levels)[-1]
print(get_level(9))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question