1. collection exercise
Obviously want to invite some students in the school together to do a survey, in order to test the objectivity of
his first computer generated random integer (N between 1 ~ 1000 N th <= 1000), N is the user input>, and for
which duplicate numbers, but one, to remove the remaining the same numerals, corresponding to the number of different students learn different number, and then put those
from small to large number of sorting, according to the investigation to find someone to do good order row, Please help obviously complete "> go heavy" and sorting work
import random
s = set([])
for i in range(int(input('N:'))):
s.add(random.randint(1,1000))
print(s)
print(sorted(s))
2. Fibonacci top twenty seeking Fibonacci number
The first:
L =[]
for i in range(20):
if i ==0 or i == 1:
L.append(1)
else:
L.append(L[i-2]+L[i-1])
print("前二十的斐波那契数:",L)
The second:
L =[]
a=0
b=1
n=0
while n < 20:
L +=[b]
a,b=b,a+b
n +=1
print("前二十的斐波那契数:",L)
Third:
L =[1,1]
while len(L)<20:
L.append(L[-1]+L[-2])
print("前二十的斐波那契数:",L)