python判斷水仙花數(函數)


def isSXH(n):
a = n % 10
b = n % 100 // 10
c = n // 100
sum = pow(a, 3) + pow(b, 3) + pow(c, 3)
if sum == n:
return True
else:
return False
isSXH = isSXH(int(input("請輸入一個三位數:")))
if isSXH:
print("是水仙花")
else:
print("不是水仙花")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM