Ask coding questions

← Back to all posts
What is wrong with my code
BrycenWeeks

Hello!

I was wondering what was wrong with my code in "Python Calculator For CSA Week 6", here is the error returned:

Voters
BrycenWeeks
Comments
hotnewtop
Coder100

hi, for more sane code, you can use fstrings, which also fix the error:

anyways the error is that python doesn't like it when you do 1 + "3" so you have to do str(1) + "3" or in your case str(int1) + "+" which is just a mouthful (textful)

CosmicBear

int1 and int2 are integers. You can't combine them with strings. Use print(str(int1) + " + "+ str(int2) + " = "+ str(res)) or use an f-string as @MrVoo said.

MrVoo

As the error says, you can't add an integer to a string. Use an f-string instead: f'{int1} + {int2} = {res}'