[英]The code to count all the 5digit number pairs such that their addition does not involve any carrying, but the code is not giving any output?
[英]to write a program to find all the pair of 5digit number such that their sum is also a 5digit number
我的學校任務是編寫一個程序來查找所有可能的 5 位數字對,這樣它們的總和也是一個 5 位數字(例如-(13526,66471),(53972+25016)等)。 我想使用基本的內置函數,如 for 和 while 循環以及 if、else 語句、列表等。
temp=[]
x=0
y=0
while x<10:
n1=[x,x,x,x,x]
x+=1
while y<10:
n2=[y,y,y,y,y]
y+=1
for i in range(0,5):
for j in range(0,5):
if n1[i]+n2[j]<=0:
temp.append((n1[i],n2[j]))
print(temp)
print(len(temp))
我嘗試了這段代碼,但正如預期的那樣它沒有工作。
我猜它應該可以工作
l=[]
n=10000
while n<100000:
for i in range(10000,100000):
s=n+i
if len(str(s))==5:
l.append(s)
else:
pass
n=n+1
print(len(l))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.