Python 7天快速入門完整視頻教程:https://www.bilibili.com/video/BV1o84y1Z7J1
Python 循環(huán)綜合案例-求水仙花數(shù)
水仙花數(shù)是指一個(gè) 3 位數(shù),它的每個(gè)數(shù)位上的數(shù)字的 3次冪之和等于它本身。例如:1^3 + 5^3+ 3^3 = 153。
參考代碼:
# 數(shù)字xyc
for x in range(1, 10):  # 百位數(shù)x 取值1-9
    for y in range(0, 10):  # 十位數(shù)y 取值0-9
        for z in range(0, 10):  # 個(gè)位數(shù)z 取值0-9
            s1 = x * 100 + y * 10 + z  # 本身值
            s2 = x ** 3 + y ** 3 + z ** 3  # 每個(gè)數(shù)位上的數(shù)字的3次冪之和
            if s1 == s2:
                print(f"水仙花有:{s1}")
作業(yè):用while循環(huán)實(shí)現(xiàn)求水仙花數(shù)
 
                