av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Python程序:檢查數字是不是Pronic數字

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

網站建設哪家好,找創(chuàng)新互聯(lián)!專注于網頁設計、網站建設、微信開發(fā)、微信小程序定制開發(fā)、集團企業(yè)網站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了廣德免費建站歡迎大家使用!

編寫一個 Python 程序來檢查一個數字是不是 Pronic 數字,或者是否使用 while 循環(huán)。例如,如果一個數等于兩個連續(xù)數的乘積,則它是一個 Pronic 數,這意味著 number = n(n + 1)。

在這個 Python 程序中,I 值從零迭代到該數字的平方根,并檢查任意兩個連續(xù)數字的乘積是否等于實際數字。如果為真,標志值變?yōu)?1,break 語句將退出循環(huán)。如果標志等于 1,則它是一個 Pronic 數。

import math

Number = int(input("Enter the Number to Check Pronic Number = "))

i = 0
flag = 0

while i <= (int) (math.sqrt(Number)):
    if Number == i * (i + 1):
        flag = 1
        break
    i = i + 1

if flag == 1:
    print("\n%d is a Pronic Number." %Number)
else:
    print("%d is Not a Pronic Number." %Number)

Python 程序,使用 for 循環(huán)檢查給定的數字是否是 Pronic 數字。

Number = int(input("Enter the Number to Check Pronic Number = "))

flag = 0

for i in range(Number + 1):
    if Number == i * (i + 1):
        flag = 1
        break

if flag == 1:
    print("\n%d is a Pronic Number." %Number)
else:
    print("%d is Not a Pronic Number." %Number)
Enter the Number to Check Pronic Number = 42

42 is a Pronic Number.

Enter the Number to Check Pronic Number = 55
55 is Not a Pronic Number.

Python 程序查找一個數字是不是 Pronic 數或者不使用函數。

def pronicNumber(Number):
    flag = 0
    for i in range(Number + 1):
        if Number == i * (i + 1):
            flag = 1
            break
    return flag

Number = int(input("Enter the Number to Check Pronic Number = "))

if pronicNumber(Number) == 1:
    print("\n%d is a Pronic Number." %Number)
else:
    print("%d is Not a Pronic Number." %Number)
Enter the Number to Check Pronic Number = 52
52 is Not a Pronic Number.

Enter the Number to Check Pronic Number = 72

72 is a Pronic Number.

網站欄目:Python程序:檢查數字是不是Pronic數字
本文網址:http://uogjgqi.cn/article/cdpgiso.html
掃二維碼與項目經理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網交流