import math
"""
水仙花数是各位立方和等于这个数本身的数
如: 153 = 1**3 + 5**3 + 3**3
"""
def lily():
for x in range(10000):
result = 0
for item in list(str(x)):
result += math.pow(int(item), 3)
if x == result:
print(x)
"""
完美数是除自身外其他所有因子的和正好等于这个数本身的数
例如: 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14
"""
def perfect():
for x in range(10000):
result = 0
for y in range(1, int(math.sqrt(x)) + 1):
if x % y == 0:
result += y
if y > 1 and x / y != y:
result += x / y
if x == result:
print(x)
"""
1只公鸡5元 1只母鸡3元 3只小鸡1元 用100元买100只鸡
问公鸡 母鸡 小鸡各有多少只
"""
def chicken():
a = 5
b = 3
c = 1/3
for x in range(0, int(100 / a) + 1):
for y in range(0, int(100 / b) + 1):
z = 100 - x - y
if a * x + b * y + c * z == 100 and x + y + z == 100:
print(str(x) + "," + str(y) + "," + str(z))
"""
输出斐波那契数列的前20个数
1 1 2 3 5 8 13 21 ...
"""
def fibonacci(arr):
temp = list(arr)
temp.append(temp[len(temp) - 1] + temp[len(temp) - 2])
if len(temp) == 20:
print(temp)
return
fibonacci(temp)
def fibonacci2():
a = 0
b = 1
for _ in range(20):
(a, b) = (b, a + b)
print(a, end=' ')
if __name__ == '__main__':
init = [1, 1]
fibonacci(init)
fibonacci2()