-1

Whenever i run my program is print the number 10 randomly and i don't know where its coming from. Anyone help me out?

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 Answers1

0

You are printing the length of the input given by user, so that's why 10 is printed out (see statement no. 6 inside main() function).

phoneNumber = str(phoneNumber)
length = len(phoneNumber)
index = 0
print(length)  # <--- this statement is printing the length of the input
Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161