每当我运行我的程序时,随机打印数字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()

答案 0 :(得分:0)
您正在打印用户给出的输入长度,以便打印10
的原因(请参阅main()函数中的语句编号6)。
phoneNumber = str(phoneNumber)
length = len(phoneNumber)
index = 0
print(length) # <--- this statement is printing the length of the input