Traceback (most recent call last):
File "\\FS2StratfordAC\ALIANWAR$\My Documents\Computing\A453 Controlled Assessment\Python\Task 3\dice game task 3 v2.py", line 52, in <module>
print ("Your total is ", str_total)
NameError: name 'str_total' is not defined*
这是我的计划的一半。
if dice1 ==dice2:
print (p1 +(" your skill is " + p1skill))
print (p1 +(" your skill is " + p1str))
print (p2 +(" your skill is " + p2skill))
print (p2 +(" your skill is " + p2str))
if dice1 > dice2:
str_total = (str_mod + p1str)
skill_total=(skill_mod + p1skill)
print (p1+ "Strength: " + str(str_val))
print (p1+ "Skill: " + str(skill_val))
print (p2+ "Strength: " + str(str_val))
print (p2+ "Skill: " + str(skill_val))
if dice2 > dice1:
str_total = (str_mod+p2str)
skill_total=(skill_mod+p2skill)
str_total = (str_mod+p2skill)
str_total=(skill_mod + p1str)
skill_total = (skill_mod - p1skill)
print ("Your total is ", str_total)
print ("Your total is ", skill_total)
还有其他未定义的东西,如第14行和第21行,未定义。任何帮助,将不胜感激。谢谢; D。
答案 0 :(得分:2)
如果dice1 == dice2
为真,则您永远不会设置str_total
和skill_total
。
当dice2 > dice1
为真时,您设置str_total
和skill_total
两次。