1
rep_number = int(input('X time(s)'))

ther_note.append(+ rep_number + "time(s).")

TypeError: unsupported operand type(s) for +: 'int' and 'str'

2

2 Answers 2

2

You cannot append a string and an integer as one element so I think the easiest way would be to cast the integer into a string with str(rep_number). You can also useformat() to generate the whole thing as a string with ("{0} times").format(rep_num).

Sign up to request clarification or add additional context in comments.

Comments

2

You can't in your example, but there are ways. If you're just getting the input to print out and won't be using it as an actual integer you can just append the formatted string using an f-string

ther_note = []
rep_number = int(input('X time(s)'))
ther_note.append(f"{rep_number} times(s)")

If you need to use the number later on, store the numbers and add the text later on when you need it.

ther_note = []
rep_number = int(input('X time(s)'))
ther_note.append(rep_number)

for x in ther_note:
    print(f"{x + 100} times(s)")

Other ways to add ints and strs:

num = 10
sentence = "My age is "
print(sentence + str(num))

Or

num = 10
sentence = "My age is {}".format(num)
print(sentence)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.