pythonfunctioncaesar-cipher

When I print from this code it returns as nonenone, Why does it do that and how can i fix it?


I am trying to create a ceasars cipher encoder but when I run this code:

def Numbererplussome(Letter):
    if Letter.lower == "a":
        Numberee = 1
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "b":
        Numberee = 2
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "c":
        Numberee = 3
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "d":
        Numberee = 4
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "e":
        Numberee = 5
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "f":
        Numberee = 6
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "g":
        Numberee = 7
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "h":
        Numberee = 8
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "i":
        Numberee = 9
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "j":
        Numberee = 10
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "k":
        Numberee = 11
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "l":
        Numberee = 12
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "m":
        Numberee = 13
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "n":
        Numberee = 14
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "o":
        Numberee = 15
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "p":
        Numberee = 16
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "q":
        Numberee = 17
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "r":
        Numberee = 18
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "s":
        Numberee = 19
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "t":
        Numberee = 20
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "u":
        Numberee = 21
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "v":
        Numberee = 22
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "w":
        Numberee = 23
        Numberee = Numberee + 3
        return Numberee
    elif Letter.lower == "x":
        int(Letter)
        Letter = 24
        Numberee = Numberee - 23
    elif Letter.lower == "y":
        Numberee = 25
        Numberee = Numberee - 23
    elif Letter.lower == "z":
        Numberee = 26
        Numberee = Numberee - 23

def UnNumberer(Numberee, NewLetterrp):
    if Numberee == 1:
        NewLetterrp = "a"
        return NewLetterrp
    elif Numberee == 2:
        NewLetterrp = "b"
        return NewLetterrp 
    elif Numberee == 3:
        NewLetterrp = "c"
        return NewLetterrp 
    elif Numberee == 4:
        NewLetterrp = "d"
        return NewLetterrp 
    elif Numberee == 5:
        NewLetterrp = "e"
        return NewLetterrp 
    elif Numberee == 6:
        NewLetterrp = "f"
        return NewLetterrp 
    elif Numberee == 7:
        NewLetterrp = "g"
        return NewLetterrp 
    elif Numberee == 8:
        NewLetterrp = "h"
        return NewLetterrp 
    elif Numberee == 9:
        NewLetterrp = "i"
        return NewLetterrp 
    elif Numberee == 10:
        NewLetterrp = "j"
        return NewLetterrp 
    elif Numberee == 11:
        NewLetterrp = "k"
        return NewLetterrp 
    elif Numberee == 12:
        NewLetterrp = "l"
        return NewLetterrp 
    elif Numberee == 13:
        NewLetterrp = "m"
        return NewLetterrp 
    elif Numberee == 14:
        NewLetterrp = "n"
        return NewLetterrp 
    elif Numberee == 15:
        NewLetterrp = "o"
        return NewLetterrp 
    elif Numberee == 16:
        NewLetterrp = "p"
        return NewLetterrp 
    elif Numberee == 17:
        NewLetterrp = "q"
        return NewLetterrp 
    elif Numberee == 18:
        NewLetterrp = "r"
        return NewLetterrp 
    elif Numberee == 19:
        NewLetterrp = "s"
        return NewLetterrp 
    elif Numberee == 20:
        NewLetterrp = "t"
        return NewLetterrp 
    elif Numberee == 21:
        NewLetterrp = "u"
        return NewLetterrp 
    elif Numberee == 22:
        NewLetterrp = "v"
        return NewLetterrp 
    elif Numberee == 23:
        NewLetterrp = "w"
        return NewLetterrp 
    elif Numberee == 24:
        NewLetterrp = "x"
        return NewLetterrp 
    elif Numberee == 25:
        NewLetterrp = "y"
        return NewLetterrp 
    elif Numberee == 26: 
        NewLetterrp = "z"
        return NewLetterrp 
    





print("hello this is a ceasers cipher encoder please type your message below")
cstr = input()
print("the encoded message should be:")
for letter in cstr:
        print(UnNumberer(Numbererplussome(letter), ""), end="")

The output returns as NoneNone when I input "hi".

I understand why print outputs none in most scenarios but why does it happen when I am returning the variable that (should) have a value?

I tried to fix this but putting all of the functions into the print function but it didn't solve my issue.

How do I add value to my (appearently) valueless variable?


Solution

  • In the code you wrote:

    def Numbererplussome(Letter):
        if Letter.lower == "a":
    

    Although the object Letter has a function called lower. You need to call the function by using Letter.lower() to get the return value, which is the lowered letter. If you just write Letter.lower, the interpreter will think that you are referring to the function itself rather than the lowered letter. And as the function is not a string and does not match any if statements, it will return None.

    Updated code:

    def Numbererplussome(Letter):
        if Letter.lower() == "a":
            Numberee = 1
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "b":
            Numberee = 2
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "c":
            Numberee = 3
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "d":
            Numberee = 4
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "e":
            Numberee = 5
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "f":
            Numberee = 6
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "g":
            Numberee = 7
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "h":
            Numberee = 8
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "i":
            Numberee = 9
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "j":
            Numberee = 10
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "k":
            Numberee = 11
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "l":
            Numberee = 12
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "m":
            Numberee = 13
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "n":
            Numberee = 14
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "o":
            Numberee = 15
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "p":
            Numberee = 16
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "q":
            Numberee = 17
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "r":
            Numberee = 18
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "s":
            Numberee = 19
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "t":
            Numberee = 20
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "u":
            Numberee = 21
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "v":
            Numberee = 22
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "w":
            Numberee = 23
            Numberee = Numberee + 3
            return Numberee
        elif Letter.lower() == "x":
            int(Letter)
            Letter = 24
            Numberee = Numberee - 23
        elif Letter.lower() == "y":
            Numberee = 25
            Numberee = Numberee - 23
        elif Letter.lower() == "z":
            Numberee = 26
            Numberee = Numberee - 23
    
    def UnNumberer(Numberee, NewLetterrp):
        if Numberee == 1:
            NewLetterrp = "a"
            return NewLetterrp
        elif Numberee == 2:
            NewLetterrp = "b"
            return NewLetterrp 
        elif Numberee == 3:
            NewLetterrp = "c"
            return NewLetterrp 
        elif Numberee == 4:
            NewLetterrp = "d"
            return NewLetterrp 
        elif Numberee == 5:
            NewLetterrp = "e"
            return NewLetterrp 
        elif Numberee == 6:
            NewLetterrp = "f"
            return NewLetterrp 
        elif Numberee == 7:
            NewLetterrp = "g"
            return NewLetterrp 
        elif Numberee == 8:
            NewLetterrp = "h"
            return NewLetterrp 
        elif Numberee == 9:
            NewLetterrp = "i"
            return NewLetterrp 
        elif Numberee == 10:
            NewLetterrp = "j"
            return NewLetterrp 
        elif Numberee == 11:
            NewLetterrp = "k"
            return NewLetterrp 
        elif Numberee == 12:
            NewLetterrp = "l"
            return NewLetterrp 
        elif Numberee == 13:
            NewLetterrp = "m"
            return NewLetterrp 
        elif Numberee == 14:
            NewLetterrp = "n"
            return NewLetterrp 
        elif Numberee == 15:
            NewLetterrp = "o"
            return NewLetterrp 
        elif Numberee == 16:
            NewLetterrp = "p"
            return NewLetterrp 
        elif Numberee == 17:
            NewLetterrp = "q"
            return NewLetterrp 
        elif Numberee == 18:
            NewLetterrp = "r"
            return NewLetterrp 
        elif Numberee == 19:
            NewLetterrp = "s"
            return NewLetterrp 
        elif Numberee == 20:
            NewLetterrp = "t"
            return NewLetterrp 
        elif Numberee == 21:
            NewLetterrp = "u"
            return NewLetterrp 
        elif Numberee == 22:
            NewLetterrp = "v"
            return NewLetterrp 
        elif Numberee == 23:
            NewLetterrp = "w"
            return NewLetterrp 
        elif Numberee == 24:
            NewLetterrp = "x"
            return NewLetterrp 
        elif Numberee == 25:
            NewLetterrp = "y"
            return NewLetterrp 
        elif Numberee == 26: 
            NewLetterrp = "z"
            return NewLetterrp 
        
    
    
    
    
    
    print("hello this is a ceasers cipher encoder please type your message below")
    cstr = input()
    print("the encoded message should be:")
    for letter in cstr:
            print(UnNumberer(Numbererplussome(letter), ""), end="")