-1

I have a very basic program which adds 2 numbers:

def addition(a, b):
    print(a + b)

addition(input("Number 1: "), input("Number 2: "))

However, the console doesn't return what I want, not adding the numbers in the way I expect. EG:

Number 1: 2
Number 2: 3
23

The console sticks them together as if they are in a list, instead of performing arithmetic! How do I stop this happening? How am I meant to add them arithmetically?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
06Days
  • 1

1 Answers1

1

The problem is that you are not doing arithmetic. You are concatenating two strings ("2" and "3"). The result of that is the string "23".

Try this:

def addition(a, b):
    print(int(a) + int(b))

addition(input("Number 1"), input("Number 2"))
Jens
  • 20,533
  • 11
  • 60
  • 86