Why is my code returning a second "matches None" line?

I have to create a function in Python that matches keypad letters with their corresponding number(excluding 1 & 0).
When I run my code and input a letter, I get the correct match, but I also get a (letter,"matches",None) line below it. What am I doing wrong and what do I need to fix to make sure that the None line doesn’t occur?
Code:

def keypad(ch):
    if ch == "A" or ch == "a" or ch == "B" or ch == "b" or ch == "C" or ch == "c":
        print(ch,"matches",2)
    elif ch == "D" or ch == "d" or ch == "E" or ch == "e" or ch == "F" or ch == "f":
        print(ch,"matches",3)

s = str(input("Enter a letter:"))
print(s,"matches",keypad(s))

Sample output for this:

Enter a letter:D
D matches 3
D matches None

>Solution :

Your keypad function calls print, which is the first output line you see. Since its doesn’t explicitly return anything, it implicitly returns None, which you then print in the last line of code.

In short, remove the print from your last call:

s = str(input("Enter a letter:"))
keypad(s)

Leave a Reply