Following up on @dirk’s suggestion, here is a solution to MIT 6.189 Homework 1 Exercise OPT.2, posted in order to stimulate discussion on other ways it could be done. One good way for us to learn would be to for us to share samples of code that we can each try out, discuss, and refine.
# MIT 6.189 Homework 1 Exercise OPT.2
phrase = raw_input("Enter sentence to encrypt: ")
# Ask for shift value; convert user input string to int
shift = int(raw_input("Enter shift value: "))
# Start with an empty string for the encoded phrase
encoded_phrase = ""
asc_a = ord("a")
asc_A = ord("A")
# Loop through each character in the phrase; use c to represent it
for c in phrase:
# Get the ascii code for the character
asc = ord(c)
if asc_a <= asc <= asc_a + 25:
# c is a lowercase letter; encode it.
asc_enc = asc_a + (asc - asc_a + shift) % 26
elif asc_A <= asc <= asc_A + 25:
# c is an uppercase letter; encode it.
asc_enc = asc_A + (asc - asc_A + shift) % 26
# c is not a letter; do not encode it.
asc_enc = asc
# Add the character to the encoded phrase.
encoded_phrase = encoded_phrase + chr(asc_enc)
print "The encoded phrase is: " + encoded_phrase
So, feel free to copy it, paste it into IDLE, run it, and then throw darts at it here, in order to get the discussion going …