设为首页收藏本站

Crossin的编程教室

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

我的python笔记Code#1

[复制链接]

1

主题

0

好友

9

积分

新手上路

Rank: 1

跳转到指定楼层
楼主
发表于 2017-7-11 10:03:05 来自手机 |只看该作者 |倒序浏览
点球大战#-*-coding:utf8;-*-
#qpy:2
#qpy:console

print "点球大战"
from random import choice#一开始浪了,使用choice没有def#
score=[0,0]
dere=['left','middle','right']
guess=['front','back']
shooter=['computer','playername']
t=0
print 'what is your name?'
shooter[1]=raw_input()
print'please guess the front or back'
if raw_input()==choice(guess):
    t=1
    print'you first'
else:
    t=0
    print'the computer first'
def goal(t):
    for i in range(1,6):
        print '======%s turn round %d======='%(shooter[t],i)
        print 'please choice your der(left,middle,right)'
        you=raw_input()
        com=choice(dere)
        k=[com,you]
        print 'computer choice the %s'%com
        if you!=com:
            print 'Goal'
            score[t]+=1
        else:
            print 'Saved'
goal(t)      
t=abs(t-1)#小得意#
goal(t)
print 'player com:you'
print  'score  %d :%d'%(score[0],score[1])


回复

使用道具 举报

1

主题

0

好友

9

积分

新手上路

Rank: 1

沙发
发表于 2017-7-11 14:17:22 来自手机 |只看该作者

成绩统计,list的操作使用和文件的读写

#-*-coding:utf8;-*-
#qpy:2
#qpy:console
import os#加入os库#
print "This is console module"
print os.getcwd()#查看当前工作路径#
os.chdir('/storage/emulated/0/qpython/scripts/')#重新定义工作路径#
f=file('tmp2.txt')
f2=file('score.txt','w')
score=[]#score初始化#
line=f.readlines()#按行读取至line#
for mun in line:#遍历line,此时mun为str#
    sumi=0
    row=mun.split()#以空格为标志.split().split('').split('a')分割mun#
    for i in row[1:]:
        sumi+=int(i)
    s='%s\t:%d\n'%(row[0],sumi)#\t制表符,\n换行#
   # print '%s score is %d'%(row[0],sumi)#
    print s
    f2.writelines(s)#按行写入#

f.close()
f2.close()
回复

使用道具 举报

174

主题

45

好友

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

板凳
发表于 2017-7-11 22:56:06 |只看该作者
最近不少同学开始发学习笔记,值得表扬啊
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

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

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

GMT+8, 2024-4-26 15:46 , Processed in 0.025267 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部