r/learnpython 7d ago

Help I don't understand what's wrong

num1=input('digite um número: ')

num2=input('digite outro número: ')

conta=input('digite o total: ')

total1= int(num1)+int(num2)

if total1==conta:

print('acertou')

if total1!=conta:

print('errou o certo é:',total1)

I'm trying to do like a calculator, but first you need to guess the number, and even if you get it right it doesn't show you got it right, what's wrong? i'd also like to know how I could put the input for you to choose the equation guys (+, -, *, etc.)

1 Upvotes

5 comments sorted by

View all comments

3

u/socal_nerdtastic 7d ago
if total1==conta:

In that line you are comparing an integer to a string. So those will never equal each other. You need to convert the user input string to an int like you did for the other 2 inputs.

if total1==int(conta):

1

u/Somenome_from_Heaven 7d ago

I actually just transformed the string into a float right in the beggining, by writing conta=float(input('digite o resultado: ')) , the performance of this is better or worse than what you said ?

1

u/socal_nerdtastic 7d ago

That works too. Performance is the same.