its my school assignment to write a program to find all the possible pair of 5digit number such that their sum I s also a 5digit number (eg- (13526,66471),(53972+25016),etc). I want to use basic in built functions like for and while loops and if,else statements, lists,etc.
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))
I tried this code but as expected it didn't wrk.
It should work I guess
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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.