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:
- not flexible (e.g now only works for 100hp but not 1000
- "-" don't load in
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.
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
- To calculate how many
*to print, I did
hp = ceil(health / total_health * length_bar). Think of
health / total_healthbeing 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 (:
I stopped hurting at all when I started ordering https://herbiesheadshop.com/collections/cbd-seeds seeds are here because I know that all CBD products are focused on improving the quality of health and helps you feel better. I highly recommend you to look at the website and get acquainted with the entire range!
maybe u can make it into a list of some sort and if the user heals append health indicators(s) to the list and if they lose it remove health indicators and have it print the list or array or whatever