Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

extract area code from phone number python

#this only works for numbers in Toronto or the greater toronto area, but its simple to expand it for more areas.
phone = input("Enter a 10 digit phone number: ")
phone = str.replace(phone, "(", "") #removes brackets
phone = str.replace(phone, ")", "") #removes brackets
phone = str.replace(phone, "-", "") #removes dashes
phone = str.replace(phone, " ", "") #removes spaces
areacode = phone[0:3]
if areacode == "416" or areacode == "647":
    print("This is a Toronto number")
elif areacode == "905" or areacode == "289":
    print("This is a GTA number")
Comment

PREVIOUS NEXT
Code Example
Python :: funcion que reciba una cadena en python 
Python :: bouon arrondi tkinter 
Python :: python adding values to existing key 
Python :: Parsing a url for IP address using python 
Python :: flask buildspec.yml 
Python :: display all rows pandas 
Python :: credential not provided when i try to sign up a new user django 
Python :: ping all ip addresses in a network 
Python :: odoo - add one2many field programmatically 
Python :: python use var in another function 
Python :: python enumerate in list comprehension with if statement 
Python :: machine learning cheatsheet activation function 
Python :: code=H18 desc="Server Request Interrupted" django 
Python :: check version of various pkgs 
Python :: can only concatenate str (not "ImageFieldFile") to str 
Python :: pil 
Python :: pandas 3d tutorail pythoin 
Python :: Fernet: Cannot decrypt strings saved in csv with pandas 
Python :: how to subtract two timestamps in python with presence of + and minus in timestamps 
Python :: copy a 2d list python 
Python :: intersection of list of sets 
Python :: how to search on wikipedia with python and speak the result 
Python :: fetch api flask url redirect 
Python :: unhexing floats 
Python :: python cv2 blob detection seg fault 
Python :: python get next item from generator 
Python :: tanimoto coefficient rdkit 
Python :: importing modules 
Python :: upper python 
Python :: python object has no attribute 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =