新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:檢查數(shù)字是不是Pronic數(shù)字
創(chuàng)新互聯(lián)python教程:

網(wǎng)站建設哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、微信小程序定制開發(fā)、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了廣德免費建站歡迎大家使用!
編寫一個 Python 程序來檢查一個數(shù)字是不是 Pronic 數(shù)字,或者是否使用 while 循環(huán)。例如,如果一個數(shù)等于兩個連續(xù)數(shù)的乘積,則它是一個 Pronic 數(shù),這意味著 number = n(n + 1)。
在這個 Python 程序中,I 值從零迭代到該數(shù)字的平方根,并檢查任意兩個連續(xù)數(shù)字的乘積是否等于實際數(shù)字。如果為真,標志值變?yōu)?1,break 語句將退出循環(huán)。如果標志等于 1,則它是一個 Pronic 數(shù)。
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)檢查給定的數(shù)字是否是 Pronic 數(shù)字。
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 程序查找一個數(shù)字是不是 Pronic 數(shù)或者不使用函數(shù)。
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程序:檢查數(shù)字是不是Pronic數(shù)字
當前路徑:http://www.dlmjj.cn/article/cdpgiso.html


咨詢
建站咨詢
