设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【Python 第28课】 字符串的分割

[复制链接]

0

主题

0

好友

50

积分

注册会员

Rank: 2

楼主
发表于 2018-5-20 14:13:54 |显示全部楼层
在接近最后的kick()显示invalid syntax是怎么回事呢,用的python 3


from random import choice

score=[0,0]
direction=['left','center','right']

def kick():
   print('==== You Kick! ====')

   print('Choose one side to shoot:')

   print('left, center, right')

   you =input()

   print('You kicked ' + you)

   com =choice(direction)

   print('Computer saved ' + com)

   if you != com:

       print('Goal!')

       score[0] += 1

   else:

       print('Oops...')

   print ('Score: %d(you) - %d(com)\n' % (score[0], score[1]))


   print('==== You Save! ====')

   print('Choose one side to save:')

   print('left, center, right')

   you =input()

   print('You saved ' + you)

   com =choice(direction)

   print('Computer kicked ' + com)

   if you == com:

       print('Saved!')

   else:

       print('Oops...')

       score[1] += 1

   print('Score: %d(you) - %d(com)\n'% (score[0], score[1]))    #列表的數字用中括號

for i in range(5):
   print('==== Round %d ====' % (i+1))
   kick()

while(score[0]==score[1]):      #平局再來
    i+=1                        #局數+1
    print('=== Round %d ==='%(i+1)  #顯示當前局數
   kick()
   
if score[0]>score[1]:
    print('You win!')

else:
    print('You Lost.')
回复

使用道具 举报

0

主题

0

好友

50

积分

注册会员

Rank: 2

沙发
发表于 2018-5-20 14:53:15 |显示全部楼层
crossin先生 发表于 2018-5-20 14:20
上一行少半个括号

是啊,解决了,谢谢老师了。这么快回覆!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-4 21:13 , Processed in 0.025337 second(s), 24 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部