tfbors
tfbors
2017-07-28 02:04
采纳率: 100%
浏览 1.5k

请大家帮我看看 Python基础改错问题谢谢(新手求助)

 from random import choice
def goal(i,score_you):
   print('========round %d u kick=========' % i+1)
   print('choose one side to shoot:')
   print(list(direction))
   you=input()
   print('you kicked'+ you)
   com=choice(direction)
   print('computer saved '+ com)
   if you != com:
       print('goal!')
       score_you += 1
   else:
       print('oops~')
def save(i,score_com):
   print('========round %d u save======== '% i+1)
   print('choose one side to save:')
   print(list(direction))
   you = input()
   print('you saved'+ you)
   com= choice(direction)
   print('computer kicked '+ com)
   if you != com:
       print('goal')
       score_com +=1
   else:
       print('oops~')


score_you = 0
score_com = 0
direction=('left','center','right')

for i in range(5):
    if (i+2)/2 == 0:
        goal(i,score_you)
        print('''round %d
            you:%d computer:%d'''% (i+1,score_you,score_com))
    else:
        save(i,score_com)
        print('''round %d
            you:%d computer:%d''' % (i + 1, score_you, score_com))

下面这是错误信息:
C:\Users\heavymetalmaniac\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/heavymetalmaniac/PycharmProjects/list_goal/goal.py
Traceback (most recent call last):
File "C:/Users/heavymetalmaniac/PycharmProjects/list_goal/goal.py", line 40, in
save(i,score_com)
File "C:/Users/heavymetalmaniac/PycharmProjects/list_goal/goal.py", line 16, in save
print('========round %d u save======== '% i+1)
TypeError: must be str, not int
应该怎么改啊
新手求助

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • shenshucong520
    glustful 2017-07-28 02:33
    已采纳

    print('========round %d u save======== '% i+1)
    TypeError: must be str, not int
    他都错误告诉你了吗,需要字符串,不能是int。
    你把i+1用括号括起来就行了吗
    print('========round %d u save======== '%(i+1))

    点赞 评论
  • tfbors
    tfbors 2017-07-28 02:34

    @gulstful 谢谢您 您能帮我看看这个怎么改吗
    Traceback (most recent call last):

    点赞 评论

相关推荐