Simple calculation | Sololearn: Learn to code for FREE!
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

8th Dec 2018, 4:11 PM
Lucy Lee
Lucy Lee - avatar
8 Respostas
+ 7
You can't add int to str in Python and you can also write print(s, '+', t, '=', c)
8th Dec 2018, 5:00 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 2
Last line is wrong. You can use f string in last line. print(f'{s}+{t}={c}')
8th Dec 2018, 4:18 PM
Maninder $ingh
Maninder $ingh - avatar
+ 2
This also work. print(s+'+'+t+'='+str(c)) But this is so complex and mysterious.
8th Dec 2018, 4:32 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
Thx! but is there any other way to code it? Iā€™m not at that stage yet haha
8th Dec 2018, 4:28 PM
Lucy Lee
Lucy Lee - avatar
+ 1
So ā€˜cā€™ should be string.... Why canā€™t I just print c without str?
8th Dec 2018, 4:41 PM
Lucy Lee
Lucy Lee - avatar
+ 1
Because it works when I print just ā€˜print(c)ā€™. I donā€™t know the difference...
8th Dec 2018, 4:41 PM
Lucy Lee
Lucy Lee - avatar
+ 1
This helps a lot! Thank you!
8th Dec 2018, 5:12 PM
Lucy Lee
Lucy Lee - avatar
0
thank you !
2nd Oct 2021, 10:45 PM
Mtr Abderrazak
Mtr Abderrazak - avatar