日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

這里有您想知道的互聯網營銷解決方案
Python程序:檢查數字是否是Harshad數字

創(chuàng)新互聯Python教程:

創(chuàng)新互聯客戶idc服務中心,提供成都機柜租用、成都服務器、成都主機托管、成都雙線服務器等業(yè)務的一站式服務。通過各地的服務中心,我們向成都用戶提供優(yōu)質廉價的產品以及開放、透明、穩(wěn)定、高性價比的服務,資深網絡工程師在機房提供7*24小時標準級技術保障。

編寫一個 Python 程序來檢查一個數字是不是 Harshad 數字,或者是否使用 while 循環(huán)。如果一個數能被給定數的位數之和整除,它就是 Harshad 數。例如,156 可以被 12 整除(1 + 5 + 6),所以它是一個 Harshad 數。

Number = int(input("Enter the Number to Check Harshad Number = "))
Sum = 0
rem = 0

Temp = Number
while Temp > 0:
    rem = Temp % 10
    Sum = Sum + rem
    Temp = Temp // 10

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

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

在這個 Python 程序中,我們使用 while 循環(huán)來劃分數字并計算所有數字的和。接下來,if 條件檢查該數是否可被 sum 整除。如果是 Tue,那就是 Harshad 數。

def digitsSum(Number):
    Sum = rem = 0
    while Number > 0:
        rem = Number % 10
        Sum = Sum + rem
        Number = Number // 10
    return Sum

Number = int(input("Enter the Number to Check Harshad Number = "))
Sum = digitsSum(Number)

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

if Number % Sum == 0:
    print("%d is a Harshad Number." %Number)
else:
    print("%d is Not a Harshad Number." %Number)
Enter the Number to Check Harshad Number = 481
The Sum of the Digits = 13
481 is a Harshad Number.

Enter the Number to Check Harshad Number = 472
The Sum of the Digits = 13
472 is Not a Harshad Number.

Python 程序,用于檢查給定的數字是否是 Harshad 數字,是否使用函數。

Sum = 0
def digitsSum(Number):
    global Sum
    if Number > 0:
        rem = Number % 10
        Sum = Sum + rem
        digitsSum(Number // 10)
    return Sum

Number = int(input("Enter the Number to Check Harshad Number = "))
Sum = digitsSum(Number)

if Number % Sum == 0:
    print("%d is a Harshad Number." %Number)
else:
    print("%d is Not a Harshad Number." %Number)
Enter the Number to Check Harshad Number = 92
92 is Not a Harshad Number.

Enter the Number to Check Harshad Number = 448
448 is a Harshad Number.

標題名稱:Python程序:檢查數字是否是Harshad數字
文章來源:http://m.5511xx.com/article/coccegg.html