Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I want to augument variable "age" on 1, but it brings me this error

I tried change print(f"Happy birthday {namename} your age is turned from{age} to {age_second}") to print(f"Happy birthday {namename} your age is turned from{age} to {age} + 1") or something that. But it hasn’t work. It following syntax of code there is introduced the second variant I tried.

namename = input("What is your name")
print(f"Hello {namename}")

age = input("How old are you?")
age_second = int({age} + 1)

print(f"Happy birthday {namename} your age is turned from{age} to {age_second}")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Outside of an F-string (f"..."), the syntax {age} means something else: it creates a set with one item (namely the value of age).

Which is why you get the error: you’re trying to add an int (1) to a set ({age}), which is an operation that Python doesn’t support.

Instead, you want to take the integer value of the input, and add one to it:

age = input("How old are you?")
age_second = int(age) + 1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading