
k=0
while k>=0:
if 5(3k)%2 == 3:
print(k)
break
k += 1
;
def cal(input="inputtxt",output="outputtxt"):
#cal方法为主程序,推荐这样做而不是PYTHONEXE xxpy xxx xxx。默认参数为python目录的两个txt,如为其他文件自己指定。
infile = file(input,"r")
#打开源数据文件
outfile = file(output,"w")
#打开目标文件
linedata = "linedata"
#初始化存储每行数据的变量
status = {}
#初始化处理的数据空间。统计的数据以字典形式存储。字典的key为人的名字,value为一个2维列表,前一个数为[发送次数,发送字节]的列表嵌套,后一个数为[接受次数,接受字节]的列表嵌套。
writedata = ""
#初始化最后准备写入的数据
while True :
linedata = infilereadline() #读取一行数据
data = linedata[:-1]split(",") #以“,”为分割符(如为其他符号自己改)
if linedata == "":
break #如果行数据为空(到文件末尾了)则跳出循环
data[2]=int(data[2]) #将“传输字节”转化为数字
if not statushas_key(data[0]):
status[data[0]] = [[1,data[2]],[0,0]] #检验如果不存在发送人名字则新建一个key,其value为[1(发送一次),发送字节数],[0(接受0次),0(发送0字节)]
else :
status[data[0]][0][1] += data[2]
status[data[0]][0][0] += 1
#如存在人名,则发送次数+1,发送字节数相加
if not statushas_key(data[1]):
status[data[1]] = [[0,0],[1,data[2]]]
else :
status[data[1]][1][1] += data[2]
status[data[1]][1][0] += 1
#这个是接受次数和接受字节数的统计
for (name,[outstatus,instatus]) in statusitems() :
writedata += name+","+str(outstatus[0])+","+str(outstatus[1])+","+str(instatus[0])+","+str(instatus[1])+"\n"
#准备写入的数据,包括 名字 逗号 发送次数 逗号 发送字节 逗号 接受次数 逗号 接受字节 换行符(如要其它输出格式自己改)
outfilewrite(writedata) #将数据写入目标文件
infileclose()
outfileclose() #关闭文件
调用方法为(假设文件名为 statuspy)。在python里面:
〉〉〉import status #载入status模块
〉〉〉statuscal() #调用cal方法
如果你还想用你原来的调用方法,就在cal方法下面加入以下内容
if __name__=='__main__':
cal()
#在windows下输入 pythonexe status就可以使用了
while True:
input = raw_input('Please enter something: ')
try:
input = int(input)
if input%2 == 0:
print input," is even number"
else:
print input," is odd number"
except:
input = str(input)
if not ' ' in input:
print input," is a string with length ",len(input)
else:
print input," is a sentence with ",inputcount(' ')," spaces"
以上就是关于求简单Python程序代码全部的内容,包括:求简单Python程序代码、求高手帮写个简单的python程序~~、Python简单小程序,十几行编码而已。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)