创新互联python教程:

创新互联公司是一家专注网站建设、网络营销策划、成都微信小程序、电子商务建设、网络推广、移动互联开发、研究、服务为一体的技术型公司。公司成立10多年以来,已经为1000+成都阳光房各业的企业公司提供互联网服务。现在,服务的1000+客户与我们一路同行,见证我们的成长;未来,我们一起分享成功的喜悦。
编写一个 Python 程序来检查一个数字是不是霓虹数字,或者是否使用 while 循环。如果一个数等于平方数位数之和,它就是霓虹数。例如,9 是一个霓虹数字,因为 92 = 81,8 +1 = 9
在这个 python 例子中,首先,我们找到一个数的平方。接下来,把那个正方形分成几个独立的数字,求出总和。如果总和等于实际数字,它就是一个霓虹数字。
import math
Number = int(input("Enter the Number to Check Neon Number = "))
Sum = 0
squr = math.pow(Number, 2)
print("Square of a Given Digit = %d" %squr)
while squr > 0:
    rem = squr % 10
    Sum = Sum + rem
    squr = squr // 10
print("The Sum of the Digits   = %d" %Sum)
if Sum == Number:
    print("\n%d is a Neon Number." %Number)
else:
    print("%d is Not a Neon Number." %Number)Python 程序检查一个数字是不是 neon 数或者不使用递归或者递归函数。
# Python Program to Check Neon Number
import math
Sum = 0
def neonNumber(squr):
    global Sum
    if squr > 0:
        rem = squr % 10
        Sum = Sum + rem
        neonNumber(squr // 10)
    return Sum
Number = int(input("Enter the Number to Check Neon Number = "))
squr = math.pow(Number, 2)
print("Square of a Given Digit = %d" %squr)
Sum = neonNumber(squr)
print("The Sum of the Digits   = %d" %Sum)
if Sum == Number:
    print("\n%d is a Neon Number." %Number)
else:
    print("%d is Not a Neon Number." %Number)Enter the Number to Check Neon Number = 44
Square of a Given Digit = 1936
The Sum of the Digits   = 19
44 is Not a Neon Number.
Enter the Number to Check Neon Number = 9
Square of a Given Digit = 81
The Sum of the Digits   = 9
9 is a Neon Number.使用 for 循环和 while 循环打印从 1 到 n 的霓虹数字的 Python 程序。
import math
MinNeon = int(input("Please Enter the Minimum Neon Value = "))
MaxNeon = int(input("Please Enter the Maximum Neon Value = "))
for i in range(MinNeon, MaxNeon + 1):
    Sum = 0
    squr = math.pow(i, 2)
    while squr > 0:
        rem = squr % 10
        Sum = Sum + rem
        squr = squr // 10
    if Sum == i:
        print(i, end = '  ')Please Enter the Minimum Neon Value = 1
Please Enter the Maximum Neon Value = 10000
1  9             
                分享文章:Python程序:检查一个数字是不是霓虹数字
                
                当前链接:http://www.csdahua.cn/qtweb/news12/307112.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网