TypeError: Can only concatenate str (not “int”) to str (simple Python programme)

后端 未结 11 651
逝去的感伤
逝去的感伤 2020-12-07 05:17

I wrote this simple code and tried to execute in Windows 10 CMD ... and it gets the error message :

TypeError: Can only concatenate str (not \"int\") to str
         


        
11条回答
  •  死守一世寂寞
    2020-12-07 05:57

    Python 3.7 this will do what you want.

    userName = input('Name: ')
    age = int(input('age: '))
    factor = 2
    finalAge = age + factor
    print("In", + factor, "years you will be", + finalAge, "years old " + userName + "!")
    

提交回复
热议问题