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

后端 未结 11 655
逝去的感伤
逝去的感伤 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 06:11

    Convert age to int to do your maths:

    finalAge = int(age) + factor
    

    And as a bonus you could use the .format() option:

    print("In {0} years you will be {1} years old, {2}!".format(factor, finalAge, userName))
    

提交回复
热议问题