设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 27284|回复: 0
打印 上一主题 下一主题

【Python 第26课】 操作list

[复制链接]

0

主题

0

好友

64

积分

注册会员

Rank: 2

楼主
发表于 2016-2-20 13:10:09 |显示全部楼层
加了一个胜负的判断,略有成就感
  1. from random import choice

  2. def function():
  3.         player=0
  4.         computer=0
  5.         print 'Choose one side to shoot:'
  6.         print 'left, center, right'
  7.         you = raw_input()
  8.         print 'You kicked ' + you
  9.         direction = ['left', 'center', 'right']
  10.         com = choice(direction)
  11.         print 'Computer saved ' + com
  12.         if you != com:
  13.                 print 'Goal!'
  14.                 player=player+1
  15.         else:
  16.                 print 'Oops...'
  17.                 computer=computer+1
  18.         return computer,player


  19. n=0
  20. while n<5:
  21.         n=n+1
  22.         list=function()

  23. if list[0]==list[1]:
  24.         print ('hhhhhh')
  25. elif list[1]<list[0]:
  26.         print ('computer win!!')
  27. else:
  28.         print ('player win!!')
复制代码
回复

使用道具 举报

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

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

GMT+8, 2024-5-6 08:30 , Processed in 0.032711 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部