IDNLearn.com: Your trusted platform for finding reliable answers. Discover prompt and accurate answers from our experts, ensuring you get the information you need quickly.
Sagot :
Answer:
In Python:
phonenum = int(input("10 digit phone number: "))
last4 = phonenum%10000
phonenum//=10000
mid3 = phonenum%1000
phonenum = phonenum//1000
newnum = str(phonenum)+"-"+str(mid3)+"-"+str(last4)
print("New: "+str(newnum))
Explanation:
This prompts the user for phone number
phonenum = int(input("10 digit phone number: "))
This gets the last 4 of the phone number using % operator
last4 = phonenum%10000
This shifts the phone number by 4 digit right
phonenum//=10000
This gets the middle 3 of the phone number using % operator
mid3 = phonenum%1000
This shifts the phone number by 3 digit right
phonenum = phonenum//1000
This generates the new phone number which includes the area code...
newnum = str(phonenum)+"-"+str(mid3)+"-"+str(last4)
This prints the formatted phone number
print("New: "+str(newnum))
Your presence in our community is highly appreciated. Keep sharing your insights and solutions. Together, we can build a rich and valuable knowledge resource for everyone. Your search for answers ends at IDNLearn.com. Thank you for visiting, and we hope to assist you again soon.