Last active
October 30, 2016 16:27
-
-
Save s2t2/b8d602baa20d54f3d83719656a962e1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
phone_input = input("Please enter a ten-digit phone number using numbers and/or capital letters (using quotation marks, e.g. '555-GET-FOOD'): ") | |
print("YOU ENTERED: " + phone_input) | |
def translate_character_to_number(char): | |
clean_char = str(char).upper() | |
if clean_char in ["A","B","C"]: | |
return "2" | |
elif clean_char in ["D","E","F"]: | |
return "3" | |
elif clean_char in ["G","H","I"]: | |
return "4" | |
elif clean_char in ["J","K","L"]: | |
return "5" | |
elif clean_char in ["M","N","O"]: | |
return "6" | |
elif clean_char in ["P","Q","R","S"]: | |
return "7" | |
elif clean_char in ["T","U","V"]: | |
return "8" | |
elif clean_char in ["X","Y","Z"]: | |
return "9" | |
else: | |
return str(char) # return the original character (e.g. '-') if it's not in the list of characters we care to translate | |
phone_number = "" | |
for char in phone_input: | |
new_char = translate_character_to_number(char) | |
phone_number += str(new_char) | |
#print("CHAR: " + char + ". NEW CHAR: " + new_char + ". PHONE NUMBER: " + phone_number) | |
print("THE NUMERIC PHONE NUMBER IS: " + phone_number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment