print("Give me two numbers and I'll add them for you\n")
num_1 = input("Enter first number: ")
num_2 = input("Enter second number: ")
answer = int(num_1 + num_2)
print(answer)
The answer I get when I add 5 + 4 is 54.
Why the code failed.
print("Give me two numbers and I'll add them for you\n")
num_1 = input("Enter first number: ")
num_2 = input("Enter second number: ")
answer = int(num_1 + num_2)
print(answer)
The answer I get when I add 5 + 4 is 54.
Why the code failed.
The input() function returns result as a str value.
"+" operation for str means concatenation, so '123' + '4' is '1234'
When you call int() function for '5' + '4' = '54' you get 54 as a result.
Correct solution is
print("Give me two numbers and I'll add them for you\n")
num_1 = int(input("Enter first number: "))
num_2 = int(input("Enter second number: "))
answer = num_1 + num_2 # this is integer value
print(answer)
num1 and num2 are strings, cast them and then perform the sum.
answer = int(num_1) + int(num_2)