日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:檢查數(shù)字是否是Krishnamurthy數(shù)字

創(chuàng)新互聯(lián)python教程:

亳州網(wǎng)站建設公司創(chuàng)新互聯(lián),亳州網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為亳州成百上千提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設要多少錢,請找那個售后服務好的亳州做網(wǎng)站的公司定做!

編寫一個 Python 程序來檢查這個數(shù)字是不是一個 Krishnamurthy 數(shù)字,或者是否使用 while 循環(huán)。如果數(shù)的階乘之和等于它自己,那么任何數(shù)都是 Krishnamurthy 數(shù)。在這個 Python 例子中,我們使用 while 循環(huán)將數(shù)字分成數(shù)字。接下來,數(shù)學階乘函數(shù)找到每個數(shù)字的階乘。if 條件檢查單個數(shù)字的階乘之和是否等于一個數(shù)字。如果是真的,這是一個 Krishnamurthy 數(shù)字。

import math

Number = int(input("Enter the Number to Check Krishnamurthy Number = "))
Temp = Number
Sum = 0

while Temp > 0:
    fact = 1
    i = 1
    rem = Temp % 10
    fact = math.factorial(rem)
    Sum = Sum + fact
    Temp = Temp // 10

if Sum == Number:
    print("\n%d is a Krishnamurthy Number." %Number)
else:
    print("%d is Not a Krishnamurthy Number." %Number)

在這個 Python 示例中,我們移除了數(shù)學階乘函數(shù),并使用嵌套的 while 循環(huán)來檢查該數(shù)是否是 Krishnamurthy 數(shù)。

Number = int(input("Enter the Number to Check Krishnamurthy Number = "))
Sum = 0
Temp = Number

while Temp > 0:
    fact = 1
    i = 1
    rem = Temp % 10

    while i <= rem:
        fact = fact * i
        i = i + 1
    print('Factorial of %d = %d' %(rem, fact))
    Sum = Sum + fact
    Temp = Temp // 10

print("The Sum of the Digits Factorials = %d" %Sum)

if Sum == Number:
    print("\n%d is a Krishnamurthy Number." %Number)
else:
    print("%d is Not a Krishnamurthy Number." %Number)
Enter the Number to Check Krishnamurthy Number = 40585
Factorial of 5 = 120
Factorial of 8 = 40320
Factorial of 5 = 120
Factorial of 0 = 1
Factorial of 4 = 24
The Sum of the Digits Factorials = 40585

40585 is a Krishnamurthy Number.

網(wǎng)站名稱:Python程序:檢查數(shù)字是否是Krishnamurthy數(shù)字
網(wǎng)頁網(wǎng)址:http://www.dlmjj.cn/article/cososhj.html