Crossin的编程教室

标题: 我的python笔记Code#1 [打印本页]

作者: Dior    时间: 2017-7-11 10:03
标题: 我的python笔记Code#1
点球大战#-*-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])



作者: Dior    时间: 2017-7-11 14:17

成绩统计,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()
作者: crossin先生    时间: 2017-7-11 22:56
最近不少同学开始发学习笔记,值得表扬啊




欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/) Powered by Discuz! X2.5