首页 > 编程语言 > 详细

python小程序

时间:2018-01-18 16:53:42      阅读:221      评论:0      收藏:0      [点我收藏+]
1.计算闰年:
def runnian(i):
if((i%4==0 and i%100!=0) or i%400==0):
return True
else:
return False
i = int(raw_input (‘year: \n‘))
print runnian(i)

2.质数:
#!/usr/bin/python

-- coding: UTF-8 --

num=[];
i=2
for i in range(2,100):
j=2
for j in range(2,i):
if(i%j==0):
break
else:
num.append(i)
print(num)

读写文件:
#--coding:utf-8
f=open(‘a.txt‘,‘w+‘)
f.write("hello\n")
a=f.tell()
print a
f=open(‘a.txt‘,‘a‘)
f.close

f=open(‘a.txt‘,‘a+‘)
#f.seek(0)
b=f.read(4)
print b

f.close

python小程序

原文:http://blog.51cto.com/406647516/2062521

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!