本文共 509 字,大约阅读时间需要 1 分钟。
1.计算闰年:
def runnian(i):if((i%4==0 and i%100!=0) or i%400==0):return Trueelse:return Falsei = int(raw_input ('year: \n'))print runnian(i)2.质数:
#!/usr/bin/pythonnum=[];
i=2for i in range(2,100):j=2for j in range(2,i):if(i%j==0):breakelse:num.append(i)print(num)读写文件:
#--coding:utf-8f=open('a.txt','w+')f.write("hello\n")a=f.tell()print af=open('a.txt','a')f.closef=open('a.txt','a+')
#f.seek(0)b=f.read(4)print bf.close
转载于:https://blog.51cto.com/406647516/2062521