def valid_phone_number(phone_number):
s = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
if " " not in phone_number or "-" not in phone_number:
return False
res = phone_number.split(" ")
if len(res) > 1:
if res[0].startswith("(") and res[0].endswith(")"):
for i in res[0][1:len(res[0])-1]:
if i not in s:
return False
else:
return False
res1 = res[1].split("-")
for i in res1:
for j in i:
if j not in s:
return False
return True
def valid_phone_number(phone_number:str):
number=['0','1','2','3','4','5','6','7','8','9']
if ' 'and '-' not in phone_number:
return False
num_list=phone_number.split(' ')
for i in range(len(num_list[0])):
if i==0:
if num_list[0][i]!='(':
return False
elif i==len(num_list[0])-1:
if num_list[0][i]!=')':
return False
else:
if num_list[0][i] not in number:
return False
if num_list[1][3]!='-':
return False
num_list2=num_list[1].split('-')
for i in num_list2:
for j in i:
if j not in number:
return False
return True