tft每日頭條

 > 科技

 > python水仙花數怎麼寫

python水仙花數怎麼寫

科技 更新时间:2024-10-11 21:24:38

初中信息技術題目:水仙花數

編寫程序,輸出所有水仙花數,一行一個。

求100~999中的水仙花數。若三位數

ABC,ABC=A3+B3+C3,則稱ABC為水仙花數。

例如153,1^3+5^3+3^3=1+125+27=153,則153是水仙花數。

實現效果如下圖:

python水仙花數怎麼寫(Python編程水仙花數)1

python水仙花數怎麼寫(Python編程水仙花數)2

Python編程代碼一:

for n in range(100,999):

a=n//100

b=n//10-a*10

c=n-b*10-a*100

if a**3 b**3 c**3==n:

print(n)

print('*'*20)

Python編程代碼二:

for n in range(100,999):

a=n//100

b=n//10

c=n

if a**3 b**3 c**3==n:

print(n)

print('*'*20)

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关科技资讯推荐

热门科技资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved