Feb-13-2018, 10:42 PM
let_to_num() takes input of a single letter, space or empty string stored in an argument variable: letter
use while key < 10: to try numbers 0 - 9 as index for phone_letters ("key" = phone dial pad key)
check if letter variable is in the index of phone_letters[key]
key = 0
while key < 10:
if # Create Code: determine if letter is **
return key
else:
key = key + 1
return "Not Found"
return the number or "Not Found"
call let_to_num() to test the function so it prints the argument and return value with:
space
lowercase letter
different letter, uppercase
a number
my code:
use while key < 10: to try numbers 0 - 9 as index for phone_letters ("key" = phone dial pad key)
check if letter variable is in the index of phone_letters[key]
key = 0
while key < 10:
if # Create Code: determine if letter is **
in
** any of the phone_letters[key] where key is the index 0 -9:return key
else:
key = key + 1
return "Not Found"
return the number or "Not Found"
call let_to_num() to test the function so it prints the argument and return value with:
space
lowercase letter
different letter, uppercase
a number
my code:
phone_letters = [' ', '', 'ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQRS', 'TUV', 'WXYZ'] def let_to_num(letter): letter=input("Enter single letter, space or empty: ") key = 0 while key < 10: for letter in phone_letters: if l in letter: return (phone_letters.index(letter)) else: key = key + 1 else: print("Not found") print(let_to_num(letter))Whatever character that I add it prints 9. I'm not sure that I even understand the task, your opinion is appreciated.