我正在创建 Python 代码,其中通过划分两个值生成的字符串值将保存到 .txt 文件中。写入文件时,值中会出现零 (0) 个字符。这是代码的相关部分:
PlayerOneSkill = str(PlayerOneSkill)
PlayerOneStrength = str(PlayerOneStrength)
PlayerTwoSkill = str(PlayerTwoSkill)
PlayerTwoStrength = str(PlayerTwoStrength)
P1SkillMod = str(P1SkillRoll12/P1SkillRoll4)
P1StrengthMod = str(P1StrengthRoll12/P1StrengthRoll4)
P2SkillMod = str(P2SkillRoll12/P2SkillRoll4)
P2StrengthMod = str(P2StrengthRoll12/P2StrengthRoll4)
f = file ("Attribute.txt","w")
f.write ("P1 skill is " + PlayerOneSkill + P1SkillMod)
f.write ("P1 strength is " + PlayerOneStrength + P1StrengthMod)
f.write ("P2 skill is " + PlayerTwoSkill + P2SkillMod)
f.write ("P2 strength is " + PlayerTwoStrength + P2StrengthMod)
f.close()
假设玩家一的属性是 12 和 16,玩家二的属性是 10 和 11,文本文件将显示:
P1 skill is 102P1 strength is 106P2 skill is 100P2 strength is 101.
零不应该在那里。