- 帖子
- 2
- 精华
- 0
- 积分
- 6
- 阅读权限
- 10
- 注册时间
- 2017-8-2
- 最后登录
- 2017-8-2
|
crossin先生 发表于 2017-8-2 19:02
这句话的前一行少了半个括号
谢谢您的解决方法,的确是那里出错。
还要叨扰下。
from random import choice
def Kick():
print("==== Round %d, - You Kick! ===="%(i+1))
print("Choose one side to shoot!")
print("'Left','Center','Right'")
you = input()
print('You kicked '+you)
com = choice(direction)
print('Com saved '+com)
if you != com:
print('Goal!')
num1 += 1
return()
else:
print('Oops!')
num2 += 1
return()
print("Score: %d(you):%d(com)"%(num1,num2))
def Save():
print("==== Round %d - You save!===="%(i+1))
print("Choose one side to save!")
print("'Left','Center','Right'")
you = input()
print("You saved " + you)
com = choice(direction)
print("Com Kicked " + com)
if you == com:
print("Saved!")
num1 += 1
return()
else:
print("Oops!")
num2 += 1
return()
print("Score: %d(you) : %d(com)"%(num1,num2))
num1 = 0
num2 = 0
direction = ['Left','Center','Right']
for i in range(5):
Kick()
Save()
报错:
Traceback (most recent call last):
File "/storage/emulated/0/qpython/project/.last_tmp.py", line 44, in <module>
Kick()
File "/storage/emulated/0/qpython/project/.last_tmp.py", line 12, in Kick
num1 += 1
UnboundLocalError: local variable 'num1' referenced before assignment
麻烦了 |
|