Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a function?
#1
Hello,

I'm very new to Python (and coding overall) and am taking my first course. Currently writing a function that takes a letter, space, or empty string as a parameter and returns the number in which it appears on a standard phone number pad:

phone_letters = [" ", "", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"]

def let_to_num(letter):
    key = 0
    while key < 10:
        if str(letter) in phone_letters[key]:
            return key
        else:
            key = key + 1
        

let_to_num(" ")
let_to_num("g")
let_to_num("M")
let_to_num(5)
When I run this code block I receive nothing in return. When I remove the last line (let_to_num(5)) I receive 6 as the only output. Can anyone tell me what needs to be fixed?

Thanks for helping a newbie!
Reply
#2
you are not capturing the return value
so:
key = let_to_num(...)
# or
print(let_to_num(...))
is what you need
Reply
#3
I knew it was a silly error, thank you.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020