如果一个3位数等于其个位数字的立方和,则称这个数为水仙花数。例如:153 = 1^3 + 5^3 + 3^3,因此153就是一个水仙花数
for i in range(100,1000):
temp = list(str(i))
a = temp[0]
b = temp[1]
c = temp[2]
if a ** 3 + b ** 3 + c ** 3 == i:
print(i)---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-1-139bf658b635> in <module> 4 b = temp[1] 5 c = temp[2]----> 6 if a ** 3 + b ** 3 + c ** 3 == i: 7 print(i)TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'有红、黄、蓝三种颜色的球,其中红球3个,黄球3个,绿球6个,先将这12个球混合放在一个盒子中,从中任意摸出8个球,编程计算摸出球的各种颜色搭配
for red in range(0,4):
for yellow in range(0,4):
for green in range(2,7):
if red + yellow + green == 8:
print("red:{}".format(red))
print("yellow:{}".format(yellow))
print("green:{}".format(green))
print("-" * 10)red:0yellow:2green:6----------red:0yellow:3green:5----------red:1yellow:1green:6----------red:1yellow:2green:5----------red:1yellow:3green:4----------red:2yellow:0green:6----------red:2yellow:1green:5----------red:2yellow:2green:4----------red:2yellow:3green:3----------red:3yellow:0green:5----------red:3yellow:1green:4----------red:3yellow:2green:3----------red:3yellow:3green:2----------原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。