-4

I am a beginner in python and am using python 3.4. I am trying to build a simple calculator. However, I keep running into this odd bug that 'incorrectly adds numbers'. say I want to do 1+1, instead of getting 2 I am getting 11.

I have tried several ways to code the problem but I still end up getting a wrong answer.

numOne = input("what is ur first number:- ")

numTwo = input("what is ur second number:- ")

add = numOne + numTwo

print(add)

Say numOne = 1, and numTwo = 1. Instead of getting 2, I am getting 11.

roganjosh
  • 12,594
  • 4
  • 29
  • 46

1 Answers1

3

You need to convert your input() which gives a string, to a int via int(input()) as follows.

numOne = int(input("what is ur first number:- "))

numTwo = int(input("what is ur second number:- "))

add = numOne + numTwo

print(add)

The output will look like:

what is ur first number:- 2
what is ur second number:- 3
5
Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40