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. Python打开新世界的大门-入门篇1

    目录 题记 Python技巧.避坑及心得 八种数据类型 循环 函数 Homework 题外话 之前没有写博客的习惯,现在开始写觉得入门也太晚了吧,看看同龄的大哥都写了十几万字.于是 ...

  2. Java核心知识盘点(二)- 缓存使用

    Redis有哪些数据类型 String.Hash.List.Set.ZSet String:字符串 Hash:哈希 Set:集合 List:列表 ZSet:有序集合 Redis内部结构 1.Redis ...

  3. leecode第二百三十八题(除自身以外数组的乘积)

    class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { int len= ...

  4. gpu相关

    1.查看cuda版本 cat /usr/local/cuda/version.txt 2.查看cudnn版本 cat /usr/local/cuda/include/cudnn.h | grep CU ...

  5. laravel框架安装Curl扩展

    然后进入根目录执行命令     composer update 完毕.

  6. 【论文速读】Multi-Oriented Scene Text Detection via Corner Localization and Region Segmentation[2018-CPVR]

    方法概述 该方法用一个端到端网络完成文字检测整个过程——除了基础卷积网络(backbone)外,包括两个并行分支和一个后处理.第一个分支是通过一个DSSD网络进行角点检测来提取候选文字区域,第二个分支 ...

  7. OLLVM特性、使用原理

    一.OLLVM特性 目前ollvm支持的特性有以下几种: 指令替换 -mllvm -sub 虚假控制流 -mllvm -bcf 打平控制流 -mllvm -fla 函数(Funtions)注解 二.指 ...

  8. 13、属性的get(存)和set(取)器

    原因:当对年龄重新进行赋值的时候就会调用set方法,然后进行判断,如果赋值小于10就会抛出异常.

  9. 2015-112 ado.net2

    CRUD:create read update delete 七. 数据绑定数据列的转换 在gridview中添加<OnRowDataBound="GridView1_RowDataB ...

  10. CentOS下运行Java文件Error: Could not find or load main class

    今天,因为测试拷贝一个JvmTest.java文件到CentOS虚机上运行,发现文件编译没有问题,但运行时却报错,如下图: Java代码如下: package com.zhi.test; public ...