tfbors 2017-07-28 02:04 采纳率: 100%
浏览 1540
已采纳

请大家帮我看看 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条回答 默认 最新

  • 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))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献