Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.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逗号和除法整数_Python_Int_Comma_Divide - Fatal编程技术网

Python逗号和除法整数

Python逗号和除法整数,python,int,comma,divide,Python,Int,Comma,Divide,示例输出为:8993/18782 我看到一些这样的问题,但都是关于“浮动”的 我想把这些整数变成这样: 8,9K/18,7K “正确”的方法是什么?试试这个功能: def SetHP(self, hpPercentage, curHP, maxHP): if not self.hpGauge.IsShow(): self.SetSize(200 + 7*self.nameLength, 70) self.hpGauge.Show() sel

示例输出为:
8993/18782

我看到一些这样的问题,但都是关于“浮动”的

我想把这些整数变成这样:

8,9K/18,7K

“正确”的方法是什么?

试试这个功能:

def SetHP(self, hpPercentage, curHP, maxHP):
    if not self.hpGauge.IsShow():
        self.SetSize(200 + 7*self.nameLength, 70)
        self.hpGauge.Show()
        self.UpdatePosition()

    self.hpGauge.SetPercentage(hpPercentage, 100)

    strCurHP = str(curHP)
    strMaxHP = str(maxHP)
    self.broadCastHP.SetText(strCurHP + " / " + strMaxHP)
def HPformat(str):
    if len(str)==5:
        newstr=str[0]+str[1] + ','+ str[2]  + 'K'
        return newstr
    elif len(str)==4:
        newstr=str[0]+','+ str[1] + 'K'
        return newstr
并将最后一行代码替换为函数:

def SetHP(self, hpPercentage, curHP, maxHP):
    if not self.hpGauge.IsShow():
        self.SetSize(200 + 7*self.nameLength, 70)
        self.hpGauge.Show()
        self.UpdatePosition()

    self.hpGauge.SetPercentage(hpPercentage, 100)

    strCurHP = str(curHP)
    strMaxHP = str(maxHP)
    self.broadCastHP.SetText(strCurHP + " / " + strMaxHP)
def HPformat(str):
    if len(str)==5:
        newstr=str[0]+str[1] + ','+ str[2]  + 'K'
        return newstr
    elif len(str)==4:
        newstr=str[0]+','+ str[1] + 'K'
        return newstr
此外,如果您不想添加新函数,可以执行以下操作:

def SetHP(self, hpPercentage, curHP, maxHP):
    if not self.hpGauge.IsShow():
        self.SetSize(200 + 7*self.nameLength, 70)
        self.hpGauge.Show()
        self.UpdatePosition()
    self.hpGauge.SetPercentage(hpPercentage, 100)

    strCurHP = str(curHP)
    strMaxHP = str(maxHP)
    self.broadCastHP.SetText(HPformat(strCurHP) + " / " + HPformat(strMaxHP))

到目前为止你有什么代码?什么?前两行甚至不是Python。你到底希望发生什么?