Here is my code below. You can change the values for the total health and the length of the bar and it should still work.
from math import ceil
total_health = 100
health = int(input("input health 1-" + str(total_health) + ":"))
brb = "x"
other_brb = "-"
length_bar = 10
#multiply x to represent hp
hp = ceil(health / total_health * length_bar)
bar = brb * hp
end_bar = other_brb * (length_bar - hp)
#add bars together
print(bar + end_bar)
This is what I changed in your code:
I used ceil( ) to round up the number so the bar shows at least one mark until health is zero. You can use round( ) instead if you want, it's up to you.
You can make the bar as long as you want by changing the value for length_bar
To calculate how many * to print, I did hp = ceil(health / total_health * length_bar). Think of health / total_health being the ratio.
I noticed in the example you use %. Modulus gives the remainder, not the quotient. Use / for division. Have a nice day, I hoped I helped (:
How to make a visual health bar? - Python 3
Ok so I have the code here but it is really inefficient ad it doesn't print the whole bar out
here are the problems:
please fix this either by editing my code or by making your own please send it to me and explain what you did thanks
Here is my code below. You can change the values for the total health and the length of the bar and it should still work.
This is what I changed in your code:
length_bar
*
to print, I didhp = ceil(health / total_health * length_bar)
. Think ofhealth / total_health
being the ratio.I noticed in the example you use
%
. Modulus gives the remainder, not the quotient. Use/
for division. Have a nice day, I hoped I helped (:Thanks
@Edgod but one thing:CN I have as much total health as i want like 23334 and the bar to still be 10 long?
yes
@Edgod I just changed total health to an input works well thanks