[英]how do i optimise this code of finding a number X whose sum with its digit is equal to n?
Find a Number X whose sum with its digits is equal to N 找到一个数字X,其数字之和等于N.
n = int(input())
for i in range(n//2, n):
z = [int(x) for x in str(i)]
zz = sum(z)
if zz<=100:
ans = int(i) + int(zz)
if(int(i) + int(zz) == n) :
print(i)
tile limit is exceeding 瓷砖限制超过
If it can be any number, this would be a fast way to do it. 如果它可以是任何数字,这将是一个快速的方法。
i = int(input("Your number: "))
result = ""
while i > 9:
result += "9"
i -= 9
result += str(i)
print(result)
How about 怎么样
for k in range(1000):
if sum([int(i) for i in str(k)]) == k:
print(k)
But there seem to be only very few numbers with that property... 但似乎只有很少的数字与该属性......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.