Skip to content

Latest commit

 

History

History
56 lines (32 loc) · 873 Bytes

Create_Phone_Number.md

File metadata and controls

56 lines (32 loc) · 873 Bytes

CodeWars Python Solutions


Create Phone Number

Definition

Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.

Example

create_phone_number([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) # => returns "(123) 456-7890"

The returned format must be correct in order to complete this challenge. Don't forget the space after the closing parentheses!


Given Code

def create_phone_number(n):
    pass

Solution 1

def create_phone_number(n):
    s = "".join([str(i) for i in n])
    return f"({s[:3]}) {s[3:6]}-{s[6:]}"

Solution 2

def create_phone_number(n):
    return "({}{}{} {}{}{}-{}{}{}{})".format(*n)

See on CodeWars.com