1 点球小游戏:

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 kickde '+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
  print '====== Round %d ======='%(i+1)
  kick()

if score[0]>score[1]:
  print 'You Win!'
else:
  print 'You lose.'


2,处理文件中的数据(学生成绩的汇总):

f=file('data.txt')
lines=f.readlines()
print lines

results=[]
for line in lines:
data=line.split()

sum=0
for score in data[1:]:
sum+=int(score)
result='%s\t:%d\n'%(data[0],sum)

results.append(result)

output=file('result.txt','w')
output.writelines(results)
output.close()


3(#),抓取百度首页的代码 保存成html文件,


4,

python入门之小栗子的更多相关文章

  1. Python入门 来点栗子

    查天气(1) http://wthrcdn.etouch.cn/weather_mini?citykey=101280804 http://wthrcdn.etouch.cn/WeatherApi?c ...

  2. Python open 读写小栗子

    1.样本内容 A.txt 2.上代码: f=open(r'E:\A.txt','r') boyA=[] boyB=[] count = for each_line in f: ]!='======': ...

  3. python入门pk小游戏

    import time import random flag = True while flag: player_win = 0 enemy_win = 0 for i in range(1, 4): ...

  4. 40个Python入门小程序

    有不少同学学完Python后仍然很难将其灵活运用.我整理 37 个Python入门的小程序.在实践中应用Python会有事半功倍的效果. 分享 Github 项目,里面收集了 Python 学习资料 ...

  5. SpringBoot+Shiro入门小栗子

    写一个不花里胡哨的纯粹的Springboot+Shiro的入门小栗子 效果如图: 首页:有登录注册 先注册一个,然后登陆 登录,成功自动跳转到home页 home页:通过认证之后才可以进 代码部分: ...

  6. 简述Python入门小知识

    如今的Python开发工程师很受企业和朋友们的青睐,现在学习Python开发的小伙伴也很多,本篇文章就和大家探讨一下Python入门小知识都有哪些. 扣丁学堂简述Python入门小知识Python培训 ...

  7. 【Python教程】《零基础入门学习Python》(小甲鱼)

    [Python教程]<零基础入门学习Python>(小甲鱼) 讲解通俗易懂,诙谐. 哈哈哈. https://www.bilibili.com/video/av27789609

  8. Python入门小练习

    Python入门小练习 001 备份文件 Python入门小练习 002 批量下载网页链接中的图片 Python入门小练习 003 利用cookielib模拟登录获取账户信息

  9. Python 入门之代码块、小数据池 与 深浅拷贝

    Python 入门之代码块.小数据池 与 深浅拷贝 1.代码块 (1)一个py文件,一个函数,一个模块,终端中的每一行都是代码块 (代码块是防止我们频繁的开空间降低效率设计的,当我们定一个变量需要开辟 ...

随机推荐

  1. Lintcode225-Find Node in Linked List-Naive

    225. Find Node in Linked List Find a node with given value in a linked list. Return null if not exis ...

  2. Lintcode93-Balanced Binary Tree-Easy

    93. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...

  3. 如何只安装Postgresql client(以9.4 为例)

    Install the repository RPM: yum install https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhe ...

  4. 数据库-left join,right join,inner join,full join

    2019-04-18 22:36:26 sql中的连接查询有inner join(内连接).left join(左连接).right join(右连接).full join(全连接)四种方式,它们之间 ...

  5. linux文件名乱码解决

    问题描述:公司的FTP服务器早就搭建好,windows客户端可以上传文件到FTP服务器,但是上传去的文件在LINUX目录下文件是乱码. 解决方法:首先编辑/etc/sysconfig/i18n这个文件 ...

  6. Confluence 6 升级中的一些常见问题

    升级的时候遇到了问题了吗? 如果你想尝试重新进行升级的话,你需要首先重新恢复老的备份.不要尝试再次对 Confluence 进行升级或者在升级失败后重新启动老的 Confluence.  在升级过程中 ...

  7. springboot killed springboot 无故停止运行解决办法

    测试环境的服务部署在阿里云服务器上,运行一段时间总是自动宕掉,在配置文件里加上内存溢出配置,也不能打印出相关日志,一直找不出原因.今天在网上:http://www.cnblogs.com/chener ...

  8. JUC原子类--01

    JUC原子操作类分为四种类型 1. 基本类型: AtomicInteger, AtomicLong, AtomicBoolean ;2. 数组类型: AtomicIntegerArray, Atomi ...

  9. Windows许可证即将到期激活教程

    电脑提示Windows许可证即将到期,于是自己就在网上找了一些教程,但是并没有激活成功,反而由即将到期变为了通知状态,尝试了各种密钥都不行,也下载了激活工具如暴风激活工具,KMS都不管用,尝试了好多方 ...

  10. h5页面避免两个页面反复跳转死循环

    项目中经常会碰到在一个页面加判断之后跳转另一个页面,并且无法返回,来回跳转,死循环,遇到这种情况可以在跳转时使用location,replace,关闭之前页面,与location.href 两者的不同 ...