Pycharm运行控制台未以正确的长度显示字符

时间:2019-07-22 21:34:06

标签: python pycharm

所以我写了一段代码来显示一些玩游戏的玩家的健康条,健康条的长度应为20个字符,但是在pycharm中运行控制台会使它的长度更大(对眼睛而言),而当我运行代码时,它会缩小并这不应该发生,健康栏的起点和终点应该保持不变,我不知道到底是什么问题!

https://ibb.co/9VmKP32 https://ibb.co/n340bZc

卸载并重新安装无效! 我将代码发送给其他人,并且确实可以正常运行,但是我不知道到底是什么问题。

def get_stats(self):

    hp_bar = ""
    mp_bar = ""
    hp_bar_ticks = (self.hp / self.maxhp) * 100 / 5
    mp_bar_ticks = (self.mp / self.maxmp) * 100 / 10

    while hp_bar_ticks > 0:
        hp_bar += "█"
        hp_bar_ticks -= 1

    while len(hp_bar) < 20:
        hp_bar += " "

    while mp_bar_ticks > 0:
        mp_bar += "█"
        mp_bar_ticks -= 1

    while len(mp_bar) < 10:
        mp_bar += " "

    hp_string = str(self.hp) + "/" + str(self.maxhp)
    current_hp = ""

    if len(hp_string) < 9:
        decreased = 9 - len(hp_string)

        while decreased > 0:
            current_hp += " "
            decreased -= 1

        current_hp += hp_string

    else:
        current_hp = hp_string

    mp_string = str(self.mp) + "/" + str(self.maxmp)
    current_mp = ""

    if len(mp_string) < 7:
        decreased = 7 - len(mp_string)

        while decreased > 0:
            current_mp += " "
            decreased -= 1

        current_mp += mp_string

    else:
        current_mp = mp_string

    print(bcolors.BOLD + self.name + "     " + current_hp + " |" + bcolors.OKGREEN
          + hp_bar + bcolors.ENDC + bcolors.BOLD + "|" + "        "+ current_mp + " |"
          + bcolors.OKBLUE + mp_bar + bcolors.ENDC + "|")

我希望输出应该以正确的长度显示!

0 个答案:

没有答案