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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:打印自然數(shù)

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

沈北新ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!

用例子寫一個 Python 程序,用 While 循環(huán)和 For 循環(huán)打印自然數(shù)。

使用 For 循環(huán)打印自然數(shù)的 Python 程序

這個用于自然數(shù)的 Python 程序允許用戶輸入任何整數(shù)值。接下來,該程序使用 For 循環(huán)打印從 1 到用戶指定值的自然數(shù)。

# Python Program to Print Natural Numbers from 1 to N

number = int(input("Please Enter any Number: "))

print("The List of Natural Numbers from 1 to {0} are".format(number)) 

for i in range(1, number + 1):
    print (i, end = '  ')

Python 自然數(shù)輸出

Please Enter any Number: 10
The List of Natural Numbers from 1 to 10 are
1  2  3  4  5  6  7  8  9  10 

使用 While 循環(huán)的 Python 自然數(shù)程序

在這個顯示自然數(shù)的 Python 程序中,我們只是將 For Loop 替換為 While Loop

# Python Program to Print Natural Numbers from 1 to N

number = int(input("Please Enter any Number: "))
i = 1

print("The List of Natural Numbers from 1 to {0} are".format(number)) 

while ( i <= number):
    print (i, end = '  ')
    i = i + 1

Python 自然數(shù)使用 while 循環(huán)輸出

Please Enter any Number: 25
The List of Natural Numbers from 1 to 25 are
1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25 

顯示一定范圍內(nèi)自然數(shù)的 Python 程序

這個用于自然數(shù)的 Python 程序與第一個示例相同。但是這次,我們允許用戶輸入最小值和最大值。這意味著這個程序打印從最小到最大的自然數(shù)。

# Python Program to Print Natural Numbers within a range

minimum = int(input("Please Enter the Minimum integer Value : "))
maximum = int(input("Please Enter the Maximum integer Value : "))

print("The List of Natural Numbers from {0} to {1} are".format(minimum, maximum)) 

for i in range(minimum, maximum + 1):
    print (i, end = '  ')


文章名稱:Python程序:打印自然數(shù)
本文網(wǎng)址:http://www.dlmjj.cn/article/dpjchid.html