2014-03-03 3 views
-2
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 번째 줄과 같이 정의되지 않은 다른 사항이 있습니다. 어떤 도움을 주시면 감사하겠습니다. 고마워.

+1

여기에 올리기 위해 올바르게 서식을 지정하는 동안 코드를 재구성하려고했습니다. 들여 쓰기가 여전히 실제 코드를 반영하는지 확인할 수 있습니까? –

답변

2

dice1 == dice2이 맞는 경우 str_totalskill_total을 설정하지 마십시오. dice2 > dice1이 true의 경우

은, 그러나, 당신은 str_total두 번skill_total 설정합니다.