随机输入求素数:
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)