练习清单
- 寻找“水仙花数”。
- 寻找“完美数”。
-
“百钱百鸡”问题。
- 生成“斐波拉切数列”。
- Craps赌博游戏。
"""
寻找水仙花数
Version:1.0
Author: sml
"""
from math import pow
for x in range(100,1000):
unit = int(x % 10)
decade = int(x%100/10)
hundreds = int(x/100)
if pow(unit,3)+pow(decade,3)+pow(hundreds,3) == x:
print(x)
"""
寻找完美数
Version:1.0
Author: sml
"""
for x in range(1,10000):
sum = 0
for i in range(1,x):
if x%i == 0 :
sum += i
if sum == x :
print(x)
"""
百鸡百钱
Version:1.0
Author: sml
"""
for x in range(20):
for y in range(33):
z = 100-x-y
if (5*x + 3*y + z/3) == 100:
print('公鸡%d 母鸡%d 小鸡%d' % (x,y,z))
"""
斐波那契数列
Version:1.0
Author: sml
"""
f1 = 1
print(f1)
f2 = 1
print(f2)
for i in range(3,100):
f3 = f2 + f1
print (f3)
f1 = f2
f2 = f3
"""
Craps 赌博游戏
Version:1.0
Author: sml
"""
from random import randint
first = randint(1,6)
second = randint(1,6)
add = first + second
print(add)
if add==7 or add==11:
print ('游戏结束,玩家赢了')
elif add==2 or add==3 or add==12:
print('游戏结束,你赢了')
else:
while True:
a = randint(1,6)
b = randint(1,6)
c = a + b
if c==add:
print(c)
print('游戏结束,玩家赢了')
break
elif c == 7:
print(c)
print('游戏结束,你赢了')
break
相关链接:
https://github.com/jackfrued/Python-100-Days/blob/master/Day01-15/Day05/%E6%80%BB%E7%BB%93%E5%92%8C%E7%BB%83%E4%B9%A0.md
网友评论