輸出“水仙花數”,所謂水仙花是指一個3位數的十進制數,其各位數字的立方和等于該數本身,例如:153是水仙花數,
用for回圈實作水仙花數的計算圖如下所示:
1 for i in range(100,1000):
2 a = i//100
3 b = (i-a*100)//10
4 c = (i-a*100-b*10)
5
6 if i == pow(a,3)+pow(b,3)+pow(c,3):
7 print(i)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/170373.html
標籤:Python
上一篇:實體007:copy
下一篇:python(os 模塊)
