answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
eimsori
2 months ago
4

Given an integer representing a 10-digit phone number, output the area code, prefix, and line number using the format (800) 555-

1212. Ex: If the input is: 8005551212 the output is: (800) 555-1212 Hint: Use % to get the desired rightmost digits. Ex: The rightmost 2 digits of 572 is gotten by 572 % 100, which is 72. Hint: Use // to shift right by the desired amount. Ex: Shifting 572 right by 2 digits is done by 572 // 100, which yields 5. (Recall integer division discards the fraction). For simplicity, assume any part starts with a non-zero digit. So 0119998888 is not allowed.
Computers and Technology
2 answers:
amid [951]2 months ago
5 0

When provided with an integer for a 10-digit phone number, format the output to display the area code, prefix, and line number as (800) 555-1212.

Examples have been considered in the code preparation.

The following code corresponds to the statement above:

Details:

phone_number = input()

if (len(phone_number)==10):

print(phone_number[0] + phone_number[1] + phone_number[2] + '-' + phone_number[3] + phone_number[4] + phone_number[ 5] + '-' + phone_number[6] + phone_number[7] + phone_number[8] + phone_number[9])

else:

print('invalid phone number')

An integer is inputted, and its length is validated.

A number that begins with 0 is not permissible.

amid [951]2 months ago
5 0

Response:

input: 8005551212

phone_number = int(input())

area_code = phone_number // 10000000

prefix = (phone_number // 10000) % 1000

line_number = phone_number % 10000

print(f'({area_code}) {prefix}-{line_number}')

Details:

#Input data

8005551212

#Assign phone number to input data

phone_number = int(input())

#Logic for determining area_code, prefix, and line_number

area_code = phone_number // 10000000

prefix = (phone_number // 10000) % 1000

line_number = phone_number % 10000

#f-strings(format strings) provide a more concise alternative for str.format() calls.

print(f'({area_code}) {prefix}-{line_number}')

You might be interested in
Within a word processing program, predesigned files that have layout and some page elements already completed are called text bo
Harlamova29_29 [1022]
I believe the answer is D. You're welcome:)
7 0
22 days ago
Write a loop that prints each country's population in country_pop. Sample output for the given program.
zubka84 [1067]

Response:

Correct script pertaining to the previous query that showcases the output.

for x, y in country_pop.items(): #this for loop iterates through the list items.

   print(str(x) + " has " + str(y) + " people") #output function to display the values.

Result:

  • This code is written in Python and produces the output required by the previous question.

Clarification:

  • The code in the previous question is intended for Python language to show the output, however, it has inaccuracies.
  • A 'for' loop is necessary, which will allow the items to be displayed one at a time.
  • The list presented is structured as key-value pairs, thus the use of the 'items' function from Python dictionaries is essential to present the list items.
  • Additionally, two variables must be established in the for loop, one representing the key and the other representing the value.
7 0
1 month ago
In Python, what kind of error is returned by the following code? (e.g. NameError, ValueError, IOError, etc.) def my_func(n1, n2)
Harlamova29_29 [1022]

Answer:

SyntaxError.

Explanation:

https://www.quora.com/In-Python-what-kind-of-error-is-returned-by-the-following-code-e-g-NameError-ValueError-IOError-etc-def-my_func-n1-n2-return-n1-n2-my_func-1-2-3          original source

brainlest plz

6 0
2 months ago
Write a Python3 program to check if 3 user entered points on the coordinate plane creates a triangle or not. Your program needs
Rzqust [1037]

Answer:

tryagain = "Y"

while tryagain.upper() == "Y":

    x1 = int(input("x1: "))

    y1 = int(input("y1: "))

    x2 = int(input("x2: "))

    y2 = int(input("y2: "))

    x3 = int(input("x3: "))

    y3 = int(input("y3: "))

    area = abs(x1 *(y2 - y3) + x2 * (y1 - y3) + x3 * (y1 - y2))

    if area > 0:

         print("Inputs form a triangle")

    else:

         print("Inputs do not form a triangle")

    tryagain = input("Press Y/y to try again: ")

Explanation:

To check for this, we will simply compute the area of the triangle given that inputs are on a coordinate plane i.e. (x,y).

An area greater than 0 means it's a triangle

Conversely, if not, it's not a triangle.

This line starts the loop with variable tryagain set to Y

tryagain = "Y"

while tryagain.upper() == "Y":

Following lines retrieve the triangle's coordinates     x1 = int(input("x1: "))

    y1 = int(input("y1: "))

    x2 = int(input("x2: "))

    y2 = int(input("y2: "))

    x3 = int(input("x3: "))

    y3 = int(input("y3: "))

Now, this computes the area

    area = abs(x1 *(y2 - y3) + x2 * (y1 - y3) + x3 * (y1 - y2))

Finally, this checks the condition mentioned above.

    if area > 0:

         print("Inputs form a triangle") This message appears if the condition is true

    else:

         print("Inputs do not form a triangle") This is printed if the condition is not met

    tryagain = input("Press Y/y to try again: ") It prompts the user to input new values

4 0
21 day ago
Dairy Farm decided to ship milk in containers in the form of cubes rather than cylinders. Write a program called ws4.cpp that pr
Harlamova29_29 [1022]

Answer:

1. #include <iostream>

2. #include <cmath>

3.  

4. using namespace std;

5.  

6. int main()

7. {

8.     float radius;  

9.     cout << "Type the radius of the base: "; // Input a number

10.     cin >> radius; // Capture user input

11.      

12.     float height;  

13.     cout << "Type the height: "; // Enter a number and press enter

14.     cin >> height; // Get user input

15.      

16.     float volumeCylinder = 3.1416 * radius * radius * height;

17.     float cubeSide = std::pow(volumeCylinder, 1/3.);

18.     cout<<"Cube side is: "<< cubeSide;

19.      

20.     return cubeSide;

21. }

Explanation:

  • Lines 1 to 5 observe two libraries
  • Lines 6 to 7 declare the main function
  • Lines 8 to 11 solicit the radius of the cylinder from the user
  • Lines 12 to 15 request the user to input the cylinder's height
  • Line 16 calculates the cylinder's volume with the formula        V=pi*(r^2)*h
  • Line 17 computes the side length of a cube with a matching volume as the cylinder using side=∛(V)
  • Lines 18 to 21 display and return the cube's side length
Download cpp
3 0
1 month ago
Other questions:
  • Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp
    6·1 answer
  • Which of the following is true? a. Pseudocode is used to describe an algorithm. b. Pseudocode is not an actual computer programm
    11·1 answer
  • To finish creating a design for the webpage, use one shape to cut away part of the other. Create a 700 pixel by 700 pixel square
    10·1 answer
  • Write a program that prompts the user to enter three cities and displays them in ascending order. Here is a sample run: Enter th
    8·1 answer
  • Which of the following does not describe local alignment algorithm?
    9·1 answer
  • Danielle, a help desk technician, receives a call from a client. In a panic, he explains that he was using the Internet to resea
    9·1 answer
  • Write the definition of a function printAttitude, which has an int parameter and returns nothing. The function prints a message
    14·1 answer
  • An extranet is like an intranet except that it allows company employees access to corporate Web sites from the ______
    13·1 answer
  • Write a program that calculates an adult's fat-burning heart rate, which is 70% of 220 minus the person's age. Complete fat_burn
    10·1 answer
  • Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!