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