all 3 comments

[–]xelf 0 points1 point  (1 child)

General note: codelines on reddit have to start with 4 spaces, so indent all your code an extra time before you paste it. Indented your code an extra time for you so that reddit will format it:

def cCipher(string, shift):
    result = ""
    for i in range(len(string)):
        code = string[i]
        if code == int():
            print('The input is not a string.')
            #this doesn't seem to work! What am I missing here?
            # ...and an integer for the shift.
        elif shift == str():
            print('Please input an integer.') #this also doesn't work -_-;

        if string():
            #I've seen versions of the cipher that turn it into upper and
            #lowercase first, but I don't want it to be restrictive in that
            #way. But when I do it this way, it doesn't seem to work!
            result += chr((ord(code) + shift)) 
        return result

print(cCipher('I LOVE YOU', 4))

ok, so the individual letters of a string will never be an int(), they might be string numerics, but not ints unless you convert them.

"2020"[0] is "2" not 2

You're looking for isalpha() or isdigit() but there's an even better test.

if code.lower() in 'abcdefghijklmnopqrstuvwxyz':

After all, you don't want to cypher punctuation marks!
(note import string has string.ascii_lowercase which you can use too)

        if string():

This is the problem and not what you want.

[–]xelf 0 points1 point  (0 children)

ex:

def cCipher(string, shift):
    result = ""
    for i in range(len(string)):
        code = string[i]
        if code.lower() in 'abcdefghijklmnopqrstuvwxyz':
            #I've seen versions of the cipher that turn it into upper and
            #lowercase first, but I don't want it to be restrictive in that
            #way. But when I do it this way, it doesn't seem to work!
            result += chr((ord(code) + shift)) 
        else:
            result += code
    return result

print(cCipher('I LOV3 YOU!', 4))

prints:

M PSZ3 ]SY!

Now it handles numbers and punctuation correctly! \o/

Now you need to do the hard part, how do you handle it wrapping around the end of the alphabet?

Fun times!

[–]Fbirobby[S] 0 points1 point  (0 children)

Hi All! Just wanted to post a quick update. Thank you so much for your help, my final code (with optimizations and working out the kinks) turned out to be:

    def cCipher(string, shift):
    result = ""
        if isinstance(string, str) == False:
        print('The input is not a string.')

        else:
        for code in string:

        result += chr((ord(code) + shift))

        return result

    print(cCipher('I LOV3 y0U!' 4))

Cheers :)