0

when input it it says:

Traceback (most recent call last):
  File "/Users/marco/PycharmProjects/pythonProject/goncas.py", line 4, in <module>
    print("A pessoa que tem "+ idade2 +" e mais velha que a pessoa que tem "+ idade)
TypeError: cannot concatenate 'str' and 'int' objects
age = int(input("Insira a sua idade"))
age2 = int(input("Insira a outra idade"))

if age <= age2:
    print("The person who has "+ age2 +" is older then the person that has "+ age)
elif age >= age2:
    print("The person who has "+ age +" is older then the person that has "+ age2)
else:
    print("Invalid data")
Barmar
  • 741,623
  • 53
  • 500
  • 612
gonsa123
  • 1
  • 1

2 Answers2

0

Use the function str(ageX), as the integer values can not converted to strings implicitly. (or don't cast it to int before)

print("The person who has "+ str(age2) +" is older then the person that has "+ str(age))
0

You can change your code like this :

print("The person who has "+ str(age2) +" is older then the person that has "+ str(age))

Because you try to add str object to int object. So python debugger can't define this operation.

eminaruk
  • 60
  • 5