How to return a string if an integer isn't a multiple of 500?

Viewed 49

Essentially I want to turn an integer hp into strings of squares.

  • I want to add a :green_square: for every 500 in hp.
  • I want to add a :red_square: for every missing 500 in hp (max hp is 10000).
  • I want to add a :yellow_square: for a remaining value between 1-499 in hp.

So far I have written:

    players = await getplayerdata()
    numofgreensqs = math.floor(hp/500)
    numofredsqs = math.floor((10000-hp)/500)
    yellowsq = ?
    hpmoji = str(numofgreensqs*":green_square:")+(yellowsq)+str(numofredsqs*":red_square:")```

So I really just need to figure out how to get the yellowsq

Edit:

   yellowsq = math.ceil((hp-(numofgreensqs*500))/500)
   hpmoji = str(numofgreensqs*":green_square:")+(yellowsq*":yellow_square:")+str(numofredsqs*":red_square:")

may have found a solution in the above. need to test though.

1 Answers
   yellowsq = math.ceil((hp-(numofgreensqs*500))/500)
   hpmoji = str(numofgreensqs*":green_square:")+(yellowsq*":yellow_square:")+str(numofredsqs*":red_square:")

This seems to work!

Related