python小程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python小程序相关的知识,希望对你有一定的参考价值。
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小程序的主要内容,如果未能解决你的问题,请参考以下文章