Question

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 phone number. Once all digits are entered, the program will display the phone number. Hint: Remember that str(num) will convert any num into a string. Here is a typical program run. The sample user input is shown in blue italics.

Input: Enter a digit: 1 Enter a digit: 4 Enter a digit: 11 Enter a digit: 2 Enter a digit: 0 Enter a digit: 21 Enter a digit: 7 Enter a digit: 9 Enter a digit: 1 Enter a digit: 0 Enter a digit: 5 Enter a digit: 4 Output: 1420791054 (or (142) 079 - 1054 for extra credit) Before beginning this project, you will document your algorithm as a list of steps to take you from your inputs to your outputs. Each step will be added as a comment block within your code. You will have the comment block right above the code that performs the actions specified. 2 For example, before your lines of code that ask the user for inputs, you would have a comment block that states what inputs you are requesting from the user.

Please see the example code provided as a sample of this. This and all program files in this course must include a comment block at the beginning (top) of the source code file that contains:

• your name

• the Python program name

• project description

• the date

The comment lines should look like this:

#############################################################################

Your name #

Python program name #

Project description #

The date

############################################################################

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

CODE IN PYTHON:

#declaring and initializing the count variable to count the valid digits
count = 0
#declaring phoneNumber variable with empty string
phoneNumber = ""
while(count<10):
#taking digit as input from the user
digit = input("Enter a digit:")
num = (int)(digit)
#checking the digit
if(num>=0 and num<=9):
phoneNumber += digit
count += 1
#displaying the final output
print("The Phone number is :",phoneNumber)

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
build a phone number from digits entered by your user. Your program will loop until 10...
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
  • With your partner, brainstorm a program that will ask the user for a number of digits...

    With your partner, brainstorm a program that will ask the user for a number of digits to be stored. The program should then create an array of that size and then prompt the user for numbers to fill each position in the array. When all of the positions are filled, display the contents of the array to the user. Create a new Project named FillArray and a new class in the default packaged named FillArray.java. You and your partner should...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    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...

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • Using C# to build this program   Digits of an Integer (Project Name: DigitParser) - Write an...

    Using C# to build this program   Digits of an Integer (Project Name: DigitParser) - Write an app that inputs one number consisting of five digits from the user, separates the number into its individual digits and displays the digits separated from one another by three spaces each. For example, if the user types 42339, the app should display 4 2 3 3 9 Assume that the user enters the correct number of digits. What happens when you execute the app...

  • In C++, Write a program that retrieves a phone number from a txt files of names...

    In C++, Write a program that retrieves a phone number from a txt files of names and phone numbers. The program should ask the user to enter a name and then print the phone number of that person (or vice versa, number into name) The program should allow the user to repeat the operation as often as they would like to. The data is contained in two text files named "phoneNames.txt" and "phoneNums.txt". The files have one name or one...

  • Q1. Write program calculate the final price of a purchased item using values entered by the...

    Q1. Write program calculate the final price of a purchased item using values entered by the user Hint: you are required to use formatting output for number, currency and percentage. --------------------[Print Receipt] ------------ Enter the quantity: 6 Enter the unit price: $1.98 Subtotals: $10.14 Tax: $ 0.61 at 6% Total: $10.75 ------------------------------------------------ Q2. Write a program that prompts for and reads the users’ first name and last name, Job title, DOB (date of Birth), and the Email address (separately). Then...

  • write a python software with the following Input The name and phone number for a contact...

    write a python software with the following Input The name and phone number for a contact Output The contents of the list after the contact has been added to the list. Processing • Welcome the user to the contact storage software. • Create 2 empty lists: one for names and one for phone numbers. Ask the user to enter the name and phone number of one new contact. Append the newly entered name to the nameList. Append the newly entered...

  • 2. Write an application that inputs a 3-digits number from the user and checks if all...

    2. Write an application that inputs a 3-digits number from the user and checks if all digits are prime numbers. If all digits are prime your program should stop. Use do/while for reading the input and any loop format to test if the number is prime. When checking the prime numbers don't use an if to check numbers from 1 - 9; you need to find an algorithm to check if the number is prime or not. Enter a 3-digit...

  • Please write a program to find the area code, exchange code, and the user number from...

    Please write a program to find the area code, exchange code, and the user number from any phone number (i.e., 10 digits) entered by the user. [hints: assume the common phone number format (3 digits area code)-(3 digits exchange code)-(4 digits user number)] in C language.

  • Write a python script that takes a six-digit integer from the user and separate the number...

    Write a python script that takes a six-digit integer from the user and separate the number into its individual digits. You program should then display each digit separated by a comma each. For example, if the user types in the number 654321, the script should display: 6,5,4,3,2,1 You can assume that the user enters the correct number of digits.

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