ashish chaudhary
Python & AII expected 15, but this code prints 105. What is the difference?
first = "10"
second = "5"
print(first + second)
CookieSensei starter Q&A · example discussion.
Loading…
I expected 15, but this code prints 105. What is the difference?
first = "10"
second = "5"
print(first + second)
CookieSensei starter Q&A · example discussion.
Quotes make these values strings. Adding strings joins their text, so "10" + "5" becomes "105". Convert valid numeric text to integers before adding when you want arithmetic. input() also returns text. In a real form or program, handle invalid input rather than assuming every string can be converted.
first = "10"
second = "5"
print(int(first) + int(second))
CookieSensei starter Q&A · example discussion.