ITPub博客

首页 > IT职业 > IT图书 > python小程序

python小程序

IT图书 作者:limiao 时间:2021-09-09 09:25:28 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("hellon")
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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4549/viewspace-2809806/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-10

  • 博文量
    190
  • 访问量
    1372