新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python 程序:打印范圍內(nèi)負(fù)數(shù)
創(chuàng)新互聯(lián)python教程:

寫一個(gè) Python 程序打印一個(gè)范圍內(nèi)的負(fù)數(shù)。這個(gè) Python 示例允許開始和結(jié)束數(shù)字,并打印該范圍內(nèi)的負(fù)數(shù)。
minimum = int(input("Enter the Minimum Number = "))
maximum = int(input("Enter the Maximum Number = "))
print("\nAll Negative Numbers from {0} and {1}".format(minimum, maximum))
for num in range(minimum, maximum + 1):
if num < 0:
print(num, end = ' ')Python 程序,使用 while 循環(huán)打印范圍為 1 到 n 的負(fù)數(shù)。
minimum = int(input("Enter the Minimum Number = "))
maximum = int(input("Enter the Maximum Number = "))
print("\nAll Negative Numbers from {0} and {1}".format(minimum, maximum))
while minimum <= maximum:
if minimum < 0:
print(minimum, end = ' ')
minimum = minimum + 1Enter the Minimum Number = -35
Enter the Maximum Number = 400
All Negative Numbers from -35 and 400
-35 -34 -33 -32 -31 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1在這個(gè) Python 示例中,negativeNumbers 函數(shù)接受兩個(gè)整數(shù)并打印它們之間的負(fù)數(shù)。
def negativeNumbers(x, y):
for num in range(x, y + 1):
if num < 0:
print(num, end = ' ')
minimum = int(input("Enter the Minimum Number = "))
maximum = int(input("Enter the Maximum Number = "))
print("\nAll Negative Numbers from {0} and {1}".format(minimum, maximum))
negativeNumbers(minimum, maximum)Enter the Minimum Number = -25
Enter the Maximum Number = 120
All Negative Numbers from -25 and 120
-25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 本文名稱:Python 程序:打印范圍內(nèi)負(fù)數(shù)
本文網(wǎng)址:http://www.dlmjj.cn/article/djcpdjp.html


咨詢
建站咨詢
