Just started following the EDX course, anyone open to give input on my code?

There are a few easy changes I'd recommend in that loop. First of all, on line 10 you're checking equality, and then on line 15 you're checking inequality for the same thing. That's a perfect opportunity to use the else statement instead. Currently you're using the else statement at the end, but it can't ever be hit.

So,

if x > (len(check)-3):
    break
elif name != check[x:y]:
    count = count
    x += 1
    y += 1
    i += 1
else:
    count += 1
    x += 1
    y += 1
    i += 1

Next, you might notice that you're always adding one to x, y and i. If that's the case, you may want to remove them from the if statement, like so:

if x > (len(check)-3):
    break
elif name != check[x:y]:
    count = count
else:
    count += 1
x += 1
y += 1
i += 1

Next let's notice that you assigned count to itself. That isn't a helpful line of code, as it doesn't change anything. We can remove that, and that whole branch of the if:

if x > (len(check)-3):
    break
elif name == check[x:y]:
    count += 1
x += 1
y += 1
i += 1

There are other issues with the code. For instance, x and i will always have the same value. Perhaps you don't need both of them?

Finally and most importantly: have you tried running this code? Does it do what you expected it to? Learning by trial and error is usually the best.

/r/learnpython Thread