Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3 ASCII代码219问题_Python_Python 3.x_Ascii - Fatal编程技术网

Python 3 ASCII代码219问题

Python 3 ASCII代码219问题,python,python-3.x,ascii,Python,Python 3.x,Ascii,我将代码与其他培训示例代码进行了比较,并进行了比较,所有内容都匹配。这是我的问题:我有一个健康条,当我受到伤害时,健康条会减少 问题是我在代码中何时使用█ 杆后的管线永远不会保持不变,它总是动态移动。当我使用/时,管杆始终保持在原位,没有问题。我猜我的终端工具(使用Pycharm)中有一些东西不喜欢ascii码219。如果阅读论坛中有问题,该工具将设置为UTF-8。下面的示例可能格式不正确,但您可以看到在使用█ 使用/时,底部很好 _____________

我将代码与其他培训示例代码进行了比较,并进行了比较,所有内容都匹配。这是我的问题:我有一个健康条,当我受到伤害时,健康条会减少

问题是我在代码中何时使用█ 杆后的管线永远不会保持不变,它总是动态移动。当我使用/时,管杆始终保持在原位,没有问题。我猜我的终端工具(使用Pycharm)中有一些东西不喜欢ascii码219。如果阅读论坛中有问题,该工具将设置为UTF-8。下面的示例可能格式不正确,但您可以看到在使用█ 使用/时,底部很好

                   ______________________________           __________ 
CARLOS:    2210/3260 |■■■■■■■■■■■■■■■■■        |   132/132 |//////////|    

                      __________________                  __________ 
CARLOS:    2219/3260 |///////////////// |        132/132 |//////////|

代码:

def get_stats(self):
    hp_bar = ""
    bar_ticks = (self.hp / self.maxhp) * 100 / 4

    mp_bar = ""
    mp_ticks = (self.mp / self.maxmp) * 100 / 10

    while bar_ticks > 0:
        hp_bar += '█'
        bar_ticks -= 1

    #num_spaces_needed = (100/4) - len(hp_bar)
    #str_spaces_needed = ""
    #while num_spaces_needed > 0:
        #str_spaces_needed += " "
        #num_spaces_needed -= 1

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

    while mp_ticks > 0:
        mp_bar += "/"
        mp_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("                      _______________________________              __________ ")
    print(bcolors.BOLD + self.name + "    " +
          current_hp + " |" + bcolors.BAR + hp_bar + bcolors.ENDC + "|    " +
          current_mp + " |" + bcolors.OKBLUE + mp_bar + bcolors.ENDC + "|    ")
def get_stats(self):
hp_bar=“”
条形刻度=(self.hp/self.maxhp)*100/4
mp_bar=“”
mp_刻度=(self.mp/self.maxmp)*100/10
当条形图刻度>0时:
hp_条+='█'
条刻度-=1
#所需空间数=(100/4)-len(hp\u条)
#str_spaces_needed=“”
#需要的空间数大于0时:
#str_空格所需+=“”
#所需空间数-=1
当len(hp_bar)<25时:
hp_条形图+=“”
当mp_刻度>0时:
mp_栏+=“/”
mp_刻度-=1
当len(mp_bar)<10时:
mp_条+=“”
hp_string=str(self.hp)+“/”+str(self.maxhp)
当前_hp=“”
如果len(hp_字符串)<9:
减少=9-长度(hp_字符串)
当减少>0时:
当前hp+=“”
减少-=1
当前\u hp+=hp\u字符串
其他:
当前\u hp=hp\u字符串
mp_string=str(self.mp)+“/”+str(self.maxmp)
当前_mp=“”
如果len(mp_字符串)<7:
减少=7-长度(mp_字符串)
当减少>0时:
当前\u mp+=“”
减少-=1
当前\u mp+=mp\u字符串
其他:
当前\u mp=mp\u字符串
打印(“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
打印(bcolors.BOLD+self.name+“”+
当前_hp+“|”+bcolors.BAR+hp_BAR+bcolors.ENDC+“|”+
当前颜色(mp+“|”+bcolors.OKBLUE+mp|bar+bcolors.ENDC+“|”)

在脚本顶部尝试以下操作:

import sys

reload(sys)
sys.setdefaultencoding('utf8')

你必须改变你的字体类型

  • 导航到文件->设置->编辑器->字体
  • 字体:源代码专业版
  • 应用->确定
  • 重新运行程序

  • 请给出实际代码的详细信息。ascii 219???你是什么意思?不要在代码中附加图像,总是以格式化文本的形式发布代码,顺便说一下,我的示例Carlos的格式不太好。希望示例代码会更有帮助。在hp_bar+='中使用ascii码219█' 它将我的第二行代码中的管道移动到最后一行。将其替换为hp_bar+=“/”没有问题,也没有发生移位。如果您需要更多的代码,请告诉我。我对Pycharm中的这个字符和其他字符也有同样的问题,默认情况下,Pycharm似乎使用了一种字体,其中一些扩展ascii字符更宽。您可以在设置中选择其他字体。