from random import random
def computer():
computer = 0
while computer < 21:
val = int(random()*10)+1
if (computer + val) > 21:
break
else:
computer += val
print "Ich habe ", computer, "!"
return computer
def player():
player = 0
loss = 0
while player < 21:
hval = int(random()*10)+1
print "Du hast ", hval, "...\nNoch eine mit y..."
if raw_input == "y":
player += hval
if player > 21:
print "Du hast verloren!"
loss = 1
break
else:
continue
else:
player += hval
break
return player
return loss
if __name__ == "__main__":
player()
if loss == 1: #This is where I get the NameError.
pass
else:
computer()
if computer > player:
print "Ich habe gewonnen!"
else:
print "Du hast gewonnen"
我在 player() 中返回了损失,所以我不知道为什么我不断收到这个 NameError。