Python alphabet shifting string
<p>i have tried but can't seem to find my mistake in my code.
My code is suppose to switch all the alphabetic characters (like a/aa/A/AA) and do nothing with the rest but when i run the code it doesn't give an error yet do what i want.</p>

<p>Could anyone tell me what i have done wrong or have forgotten?</p>

<pre><code>letter = input("type something")
shift = int(input("type how many shifts"))
if letter in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']:
    a = ord(letter) + shift
    b = chr(a)
    print(b)
else: 
    print(letter)
</code></pre>

<p>EDIT: thanks for the == replacement for in! Does someone know why using more than one character in letter gives the same print?(Desired output: when i put in abc and 1 i want it to print bcd)</p>

<p>I suppose you want to shift the letters so if the input letter is 'a' and shift is 3, then the output should be 'd'.</p>

<p>In that case replace</p>

<pre><code>if letter == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']:
</code></pre>

<p>with</p>

<pre><code>if letter in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']:
</code></pre>

<p>Or better yet as Tempux suggested you can use </p>

<pre><code>if letter.isalpha()
</code></pre>

<p>If you want to shift multple letters you need to loop across each character. Try the following code for multiple letters</p>

<pre><code>letter = input("type something")
shift = int(input("type how many shifts"))
s = ""
for l in letter:
    if l.isalpha():
        a = ord(l) + shift
        s += chr(a)
    else: 
        s += l

print(s)
</code></pre>

python algorithm