以下是我到目前为止的情况,尽管它不能正常工作。如有任何修改建议,敬请谅解。在def get_telephone_number(areacode, prefix, number):
set1 = areacode[0:3]
set2 = prefix[0:3]
set3 = number[-3:]
telephone_number=set1 + '-' + set2 + '-' + set3
return get_telephone_number
def valid_telephone_number(telephone_number):
correct_length = False
proper_hyphens = False
has_digits = False
if len(telephone_number) == 12:
correct_length = True
for ch in telephone_number:
if ch [3, 7] == '-':
proper_hypens = True
if ch.isdigit():
has_digits = True
if correct_length and proper_hypens and has_digits:
is_valid = True
else:
is_valid = False
return is_valid
###########
import telephone_number
def main():
phone_number = input('Enter your telephone number: ')
while not phone_number.valid_telephone_number(telephone_number):
print('That number is invalid.')
phone_number = input('Enter your telephone number: ')
print('That is a valid entry.')
main()