TypeError: not all arguments converted during string formatting

Dung Do Tien Mar 17 2021 22

Hello, I  am a beginner in Python.  And I have created a simple code as below:

#!/usr/bin/env python
firstName = input("Enter name 1: ")
lastName = input("Enter name 2: ")
len(firstName)
len(lastName)
if len(firstName) == len(lastName):
    if firstName == lastName:
        print ("Your name is beautiful")
    else:
    if len(firstName) > len(lastName):
        print ("Your name is '{0}' '{1}'"% firstName, lastName)
    elif len(firstName) < len(lastName):
        print ("Your name is '{0}' '{1}'"% lastName, firstName)

But when run this code I got an error : TypeError: not all arguments converted during string formatting.

Please tell me why if you have any suggestions.

Have 1 answer(s) found.
  • To addition string in Python you can use the '%' operator is to use a printf-style format string, See as below:

    print ("Your name is %s %s" %(name1, name2))

    Other way you can use format function to do:

    print("Your name is '{0}' '{1}'".format(firstName, lastName))
    
    Sandeep Kumar Mar 17 2021
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close