"
ret += '' + Name + " | "
- ret += "" + str("%.0f" % float(UnitDict["HP"])) + " | "
- ret += "" + str("%.0f" % float(UnitDict["BuildTime"])) + " | "
- ret += "" + str("%.1f" % float(UnitDict["WalkSpeed"])) + " | "
+ ret += "" + str("{:.0f}".format(float(UnitDict["HP"]))) + " | "
+ ret += "" + str("{:.0f}".format(float(UnitDict["BuildTime"]))) + " | "
+ ret += "" + str("{:.1f}".format(float(UnitDict["WalkSpeed"]))) + " | "
for atype in AttackTypes:
PercentValue = 1.0 - (0.9 ** float(UnitDict["Resistance"][atype]))
ret += (
""
- + str("%.0f" % float(UnitDict["Resistance"][atype]))
+ + str("{:.0f}".format(float(UnitDict["Resistance"][atype])))
+ " / "
+ str("%.0f" % (PercentValue * 100.0))
+ "% | "
@@ -325,28 +325,28 @@ def WriteUnit(Name, UnitDict):
ret += "" + str("%.1f" % (float(UnitDict["RepeatRate"][attType]) / 1000.0)) + " | "
else:
- for atype in AttackTypes:
+ for _ in AttackTypes:
ret += " - | "
ret += " - | "
if UnitDict["Ranged"] is True and UnitDict["Range"] > 0:
- ret += "" + str("%.1f" % float(UnitDict["Range"])) + " | "
+ ret += "" + str("{:.1f}".format(float(UnitDict["Range"]))) + " | "
spread = float(UnitDict["Spread"])
- ret += "" + str("%.1f" % spread) + " | "
+ ret += "" + str(f"{spread:.1f}") + " | "
else:
ret += " - | - | "
for rtype in Resources:
- ret += "" + str("%.0f" % float(UnitDict["Cost"][rtype])) + " | "
+ ret += "" + str("{:.0f}".format(float(UnitDict["Cost"][rtype]))) + " | "
- ret += "" + str("%.0f" % float(UnitDict["Cost"]["population"])) + " | "
+ ret += "" + str("{:.0f}".format(float(UnitDict["Cost"]["population"]))) + " | "
ret += ''
for Bonus in UnitDict["AttackBonuses"]:
ret += "["
for classe in UnitDict["AttackBonuses"][Bonus]["Classes"]:
ret += classe + " "
- ret += ": %s] " % UnitDict["AttackBonuses"][Bonus]["Multiplier"]
+ ret += ": {}] ".format(UnitDict["AttackBonuses"][Bonus]["Multiplier"])
ret += " | "
ret += "
\n"
@@ -370,7 +370,7 @@ def SortFn(A):
def WriteColouredDiff(file, diff, isChanged):
- """helper to write coloured text.
+ """Helper to write coloured text.
diff value must always be computed as a unit_spec - unit_generic.
A positive imaginary part represents advantageous trait.
"""
@@ -378,8 +378,7 @@ def WriteColouredDiff(file, diff, isChanged):
def cleverParse(diff):
if float(diff) - int(diff) < 0.001:
return str(int(diff))
- else:
- return str("%.1f" % float(diff))
+ return str(f"{float(diff):.1f}")
isAdvantageous = diff.imag > 0
diff = diff.real
@@ -392,16 +391,14 @@ def WriteColouredDiff(file, diff, isChanged):
if diff == 0:
rgb_str = "200,200,200"
- elif isAdvantageous and diff > 0:
- rgb_str = "180,0,0"
- elif (not isAdvantageous) and diff < 0:
+ elif isAdvantageous and diff > 0 or (not isAdvantageous) and diff < 0:
rgb_str = "180,0,0"
else:
rgb_str = "0,150,0"
file.write(
- """