电话号码格式化Python

时间:2016-12-12 20:06:49

标签: python modular

每当我运行我的程序时,随机打印数字10,我不知道它的来源。有人帮帮我吗?



def main():
    phoneNumber=int(input("Enter a 10 digit unformatted telephone number in the format ##########: "))
    tempNumber = []
    phoneNumber = str(phoneNumber)
    length = len(phoneNumber)
    index=0
    print(length)


    if (length ==10):
        print("The unformatted number is: ",phoneNumber)
    else:
        print("The telephone number was NOT entered in unformatted format ##########.")

    for num in phoneNumber: 
        tempNumber.append(num)

    tempNumber.insert(0,"(")
    tempNumber.insert(4,")")
    tempNumber.insert(8,"-")
    phoneNumber = ''.join(tempNumber)
    print("The formatted number is: ",phoneNumber)

main()




1 个答案:

答案 0 :(得分:0)

您正在打印用户给出的输入长度,以便打印10的原因(请参阅main()函数中的语句编号6)。

phoneNumber = str(phoneNumber)
length = len(phoneNumber)
index = 0
print(length)  # <--- this statement is printing the length of the input