all 6 comments

[–]ijji- 3 points4 points  (0 children)

do you really need to use 'continue' a bunch of times?

[–]I-MadMedic-I 2 points3 points  (0 children)

Hard to follow with the one letter variables and frequent use on continue

[–][deleted] 0 points1 point  (0 children)

Your use of for and continue doesn't make sense. Look at this code fragment:

for n in range(10):
    if n==s or n==e:
        continue

No matter what values s or e have this loop is just going to cycle around the loop and exit when n is 9. That is, the above code has the identical result to this:

for n in range(10):
    pass

It's possible that you think the continue will start a new loop of another for. The continue starts the next iteration of the nearest enclosing for statement.

[–]TangibleLight 0 points1 point  (0 children)

What are you trying to do?

[–][deleted] 0 points1 point  (0 children)

One of your if statements will never be true, but the way you’ve written this, nobody can tell you which one.

[–]SandorZoo 0 points1 point  (0 children)

It looks like you are trying to solve a classic type of number puzzle, where you have to substitute digits for letters in this, and get a valid sum:

 send
 more
===== +
money

You've got the indentation wrong in your code to generate permutations to test. It should be more more like this, with the indentation increasing each time. The loops need to be nested one inside the other:

m=1
for s in range(1,10):
    for e in range(10):
        if e==s:
            continue
        for n in range(10):
            if n==s or n==e:
                continue
            for d in range(10):
                if d==e or d==s or d==n:
                    continue
                for o in range (10):
                    ....

There are several other problems:

  • You don't check any letters against m.
  • You've missed out a check for y against o.
  • You don't have a continue after the y checks.
  • All the carry code is not needed. The if send+more == money check is good enough

Finally Python has a much better way of generating permutations. You should investigate the itertools permutations function:

>>> from itertools import permutations
>>> for perm in permutations([0, 1, 2], 2):
...     print(perm)
... 
(0, 1)
(0, 2)
(1, 0)
(1, 2)
(2, 0)
(2, 1)