My code takes a string that's been simply encrypted using an alphabetic character shift method, decodes it, and outputs the line in it's original form. So if the shift was -2, "d" would be "b" etc. Problem is when I use a forloop, it skips any spaces in a string. I need to output the code with the spaces, and splitting the string to keep the words separate seems like a really complicated way of doing it. Any hints? Thanks plenty in advance

for char in code: if char == ' ': continue #if we haven't continued, we can shift after this

Also, it's probably a good idea to create a list and then use str.join() on it rather than string concatenation in the for loop. Also, you code could shift letters into non-letter ASCII characters. Is this intentional? If not, you might want to look into str.translate() and string.maketrans().

for char in code: if char == ' ': continue #if we haven't continued, we can shift after this

Also, it's probably a good idea to create a list and then use str.join() on it rather than string concatenation in the for loop. Also, you code could shift letters into non-letter ASCII characters. Is this intentional? If not, you might want to look into str.translate() and string.maketrans().

I was actually using that type of loop initially, but I changed it to the index loop to see if that would stop it from skipping spaces, which it didn't, so I'll change it back as you suggest. Shifting to non-ASCII letters wasn't intentional, it's just something I hadn't got to addressing yet because the space skipping seems like it should be my first priority. I'll look into those methods too, but I want to code with my basic knowledge first before increasing my language "vocabulary" further just so there's more problems and things on which to practice on in the meantime.

I just fiddled about with it some more, and it seems my loop was ignoring spaces because whatever chr(ord(" ")-1) is, it returns as a stripping of the space. When I wrote chr(ord(" ")+1), it returned "!", so at least I understand what was going on there (and the length of the string remains the same).

So with the if condition, I can add that space to the string either by writing a str.join() or by concatenation before the continue statement, right?