Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to shift letters in python after the user inputs a shift number and a message?

I don’t have any code but I am really stuck on how to shift letters based off an input. e.g: the user inputs 1 so A is B and B is C etc.

alphabet = ['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']

direction = input("Type 'encode' to encrypt, type 'decode' to 
decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am providing a basic solution for your problem, modify if to suit your needs.

alphabet = [
    "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",
]
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))

new_text = ""
for character in text:
    new_text += chr(ord(character) + shift)

print(new_text)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading