-1

When I enter my variable into the line I get the TypeError.

num = int(input("Enter a number"))
print("You are " + num * 7 + " dog years old")

I expect it to just take the input then multiply it by 7 and give the final number, but I just get the error. I barely understand str and int so an explanation of each would help too.

Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
  • You cannot concatenate string and integer. See the documentation of string. https://docs.python.org/3/library/stdtypes.html#str I think you are looking for something like: `print("You are " + str(num * 7) + " dog years old")` – rzskhr Feb 13 '19 at 00:33
  • If you are using a recent python, you can do print(f"You are {num*7} dog years old") – Axeon Thra Feb 13 '19 at 00:47

1 Answers1

1

Convert the number to a string:

num = int(input("Enter a number."))
print ("You are " + str(num * 7) + " dog years old")

As the error states, you cannot concatenate strings and ints:

TypeError: cannot concatenate 'str' and 'int' objects?

Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65