Given a long 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 des

Respuesta :

Answer:

# User is prompted to enter phone number

phone_number = int(input("Enter your 10-digit phone number: "))

# this modulus operation will give the last 4 digit

# as the line number

line_number = phone_number % 10000

# this integer division will give a combination

# of area code and prefix

area_code_prefix = phone_number // 10000

# this integer division of the area_code_prefix

# will give the area_code

area_code = area_code_prefix // 1000

# this modulo operation of the area_code_prefix

# will give the prefix

prefix = area_code_prefix % 1000

# the phone number is printed in the specified format

print('(',area_code,')',' ',prefix,'-',line_number, sep='')

Explanation:

A sample image of program output is attached.

Ver imagen ibnahmadbello

The program is an illustration of modulo operator.

The modulo operator is used to perform return the remainder of a division operation

The program in Python where comments are used to explain each line is as follows:

#This gets input for the phone number

phone = int(input("10-digit phone number: "))

#This calculates the line number

line = phone % 10000

#This calculates the area code

area_code = (phone // 10000)// 1000

#This calculates the prefix

prefix = (phone // 10000) % 1000

#This prints the required output

print('('+str(area_code)+')'+' '+str(prefix)+'-'+str(line))

Read more about similar programs at:

https://brainly.com/question/13549861