You have a couple of logic problems here. The first is your loop control. You start with
a=10
for i in range(100):
a+=1
This will run a
over the range 10 to 10+100. Now, for each value of a
, you do:
b=10
...
for i in range(100):
b+=1
First of all, you've changed the value of i
, which the outer loop is still trying to use. This is the first problem, the one that's killing your current program. Second, if you fix this by changing the loop index to j
(for instance), then you will increment b
100*100 times, so it ends up at 10010.
On top of this, a
and b
are never individual digits! You've started each as a 2-digit number.
Instead, make two changes:
- Put the values you actually want into the
for
loop.
Use strings, not integers, if that's what you're trying to do.
for a in "0123456789":
for b in "0123456789":
if int(a+b) + int(b+a) == 88:
This code makes 2-digit strings. Another way is to work with the single-digit integers, but then use algebra to make the 2-digit numbers:
if (10*a + b) + (10*b + a) == 88:
Finally, you can simplify the entire process by doing basic algebra on the above expression:
(10*a + b) + (10*b + a) == 88
11*a + 11*b == 88
a + b = 8
From here, you note simply that b = 8-a
, and you can reduce your program to a single loop.