当前分类:300例题>>正文

Python示例:打印从 1 到 100 的数字

来源:互联网   更新时间:2023年6月19日  

Python 示例

编写一个 Python示例来打印从 1 到 100 或在一定范围内的数字。这个 Python 示例接受最小值和最大值,并显示该范围内的数字。

import math

def digitsCount(Number):
    length = 0
    while Number != 0:
        length = length + 1
        Number = Number // 10
    return length

def digitsSum(Number):
    Sum = 0
    rem = 0
    length = digitsCount(Number)
    while Number > 0:
        rem = Number % 10
        Sum = Sum + math.pow(rem, length)
        Number = Number // 10
        length = length - 1
    return Sum

minDis = int(input("Enter the Minimum Disarium Number = "))
maxDis = int(input("Enter the Maximum Disarium Number = "))

print("\nThe List of Disarium Numbers from {0} and {1}".format(minDis, maxDis)) 
for i in range(minDis, maxDis):
    Sum = digitsSum(i)

    if Sum == i:
        print(i, end = "   ")

本文固定链接:https://6yhj.com/leku-p-4317.html  版权所有,转载请保留本地址!
[猜你喜欢]

标签: ddos