Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
Simple calculation
Hi! I want a result like below. Input the first number 7 Input the second number 8 7+8 = 15 And what I did was below print(āInput the first numberā) s=input() print(āInput the second numberā) t=input() c=int(s) + int(t) print(s ā+ā t ā=ā c) What was wrong? Please help Also, if there is other way I can code (especially the last line) please advise
8 Respostas
+ 7
You can't add int to str in Python and you can also write
print(s, '+', t, '=', c)
+ 2
Last line is wrong. You can use f string in last line.
print(f'{s}+{t}={c}')
+ 2
This also work.
print(s+'+'+t+'='+str(c))
But this is so complex and mysterious.
+ 1
Thx! but is there any other way to code it? Iām not at that stage yet haha
+ 1
So ācā should be string....
Why canāt I just print c without str?
+ 1
Because it works when I print just āprint(c)ā.
I donāt know the difference...
+ 1
This helps a lot! Thank you!
0
thank you !