Question

This is Python

The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12.

The program should not crash if the user enters invalid characters for the phone number (should be letters, digits and/or "-" (hyphen or dash) The first character cannot be a dash, and the last four characters cannot contain any dashes. The user input should not be case sensitive.

If the user enters an invalid characters on input, the program should print an appropriate error message (not just "oops!") and the user should be invited to try again, until they enter a valid phone number or type "quit".

Users should enter as many phone numbers as they want until they type "quit", at which case the program says good-bye and prints the programmer's name.

Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def convert(n):
if(n=="A" or n=="B" or n=="C"):
num=2
elif(n=="D" or n=="E" or n=="F"):
num=3
elif(n=="G" or n=="H" or n=="I"):
num=4
elif(n=="J" or n=="K" or n=="L"):
num=5
elif(n=="M" or n=="N" or n=="O"):
num=6
elif(n=="P" or n=="Q" or n=="R" or n=="S"):
num=7
elif(n=="T" or n=="U" or n=="V"):
num=8
elif(n=="W" or n=="X" or n=="Y" or n=="Z"):
num=9
else:
num=-1
return num
  
def validate(number):
if number[0]=="-":
print("The first character cannot be a dash")
return False
elif number[len(number)-1]=="-" or number[len(number)-2]=="-" or number[len(number)-3]=="-" or number[len(number)-4]=="-":
print("The last four characters cannot contain any dashes")
return False
  
number=number.replace("-","")
  
if len(number)==10 or len(number)==7:
new_number=""
if(len(number)==7):
new_number="512"
for i in range(0, len(number)):
if(number[i].isalpha()):
new_number+=str(convert(number[i]))
if(int(convert(number[i]))==-1):
print("Number contains invalid characters")
break
else:
new_number+=number[i]
n2=new_number[:3]+"-"+new_number[3:6]+"-"+new_number[6:]
print(n2)
return True
else:
print("Length is not 7 or 10")
return False
  
name=input("Enter your name: ")   
while True:
number=input("Enter 10 character telephone number: ")
if validate(number.upper()):
break
else:
stri =input("Invalid number, Want to try again?or enter quit ")
if(stri=="quit"):
break
print("Goodbye "+name+"!!")

Screenshot of code

def convert(n): if(n==A or n==B or n==C): num=2 elif(n==D or n==E or n==F): num=3 elif(n==G or n== ==H or n=

def validate(number): if number[@]==-: print(The first character cannot be a dash) return false elif number (number)-1)==

Output Screens

input Enter your name: John Enter 10 character telephone number: 555-get-Food 555-438-3663 Goodbye John!!input Enter your name: Jane Enter 10 character telephone number: 125478-PL- The last four characters cannot contain any dashe

Add a comment
Know the answer?
Add Answer to:
This is Python The program should accept input from the user as either 7-digit phone number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Help with programming in Raptor: Many companies use telephone numbers like 555-GET-FOOD so the number is...

    Help with programming in Raptor: Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion: A, B, and C = 2 D, E, and F = 3 G, H, and I = 4 J, K, and L = 5 M, N, and O = 6 P, Q, R, and S = 7 T, U, and V = 8...

  • I'm quite stuck with this C++ question, I would greatly appreciate the help! Many companies use...

    I'm quite stuck with this C++ question, I would greatly appreciate the help! Many companies use telephone number like 888- COM - CAST so the number is easier for their customer to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion. A, B, and C = 2 D, E, and F = 3 G, H, and I = 4 J , K , and L = 5 M, N, and O = 6...

  • Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the...

    Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the user to enter a string. The string will then be displayed back to the user. This is followed by determining the number of alphabetic characters, numeric characters, lower_case letters, upper_case letters, whitespace characters, and then displaying them. The user should be given additional chances to enter additional strings, and each time a string is entered, the above process is to be performed. The inputting...

  • Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use...

    Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use digits and letters (or only letters) to show their telephone number. In some cases, to make a telephone number meaningful, companies might use more than seven digits and letters. Here are some examples: Phone Number in Display Note Actual Phone Number GET LOAN - 438-5626 CALL HOME More than seven digits/letters used for ease of remembrance. 225-5466 111 GOLD - 111-4653 Glass4u - 452-7748...

  • Numbers with embedded dashes play a huge role in our lives. Think of your phone number...

    Numbers with embedded dashes play a huge role in our lives. Think of your phone number or Social Security number. Write a program that uses a Scanner to take a single line of user input. You may assume this input consists of any number of characters and contains zero, one or two dashes. Use only String's indexOf, lastIndexOf, and substring methods. Sample input might be 123-45-6789 or 919-555-1212 or hare-brained Your program should remove the dashes and print the digits....

  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone...

    Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone numbers easier to remember, some companies use letters to show their telephone number, but mapping the letters to the numbers on a standard telephone keypad: 1 2 ABC 3 DE 4G 5 11 6 MNO 7 PONS 8 Tu 9.xyz # For example, using letters & spaces, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone...

  • 4B : C PROGRAMMING To make telephone numbers easier to remember, some companies use letters to...

    4B : C PROGRAMMING To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters & spaces, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME,which uses eight letters. Write a program that prompts the user to enter a telephone number expressed in letters/spaces and...

  • build a phone number from digits entered by your user. Your program will loop until 10...

    build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and 9 inclusively. If so, the digit will be stored as the next number in the...

  • Write a function called "phoneNumberFormat" that takes a string containing a ten-digit phone number (such as...

    Write a function called "phoneNumberFormat" that takes a string containing a ten-digit phone number (such as 5155551212) as input, convert into a more readable string with parentheses and dashes like (515)555-1212 and display it. If the input string contains more than or less than ten characters, display an error message. Note: Steps of phoneNumberFormat function can be given as follows: def phoneNumberFormat (phoneNum): 1. Let l be the length of the phoneNum 2. If 1 does not equal 10 then,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT