python几个练习(素数、斐波那契数列)

随机输入求素数:

x = int(input("please enter the number:"))
if x != 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x)

求10W以内全部的素数

c = 0
for x in range(2,100000):
for i in range(2, int(x ** 0.5)+1):
if x % i == 0:
break
else:
c += 1
print(x) print(c)

 求斐波那契数列的101项

x = 0
y = 0
for i in range(0, 102):
if i == 0:
y = 1
elif i == 1:
x = 1
y = 1
else:
tmp = y
y = x + y
x = tmp
print(y)
print(y)

  

 

上一篇:解决mint17-linux里chrome一搞就弹出“登陆密钥环”的框框


下一篇:warning LNK4099: PDB 原因及解决方案