-1

feed function using raw_input of sys.argv for sum of two number goes just showing in list

def sum_double(a, b):
    sum = a+b
    if a == b:
            sum = sum*2
            print sum
            return sum
    else :
            print sum
            return  sum
sum_double(a = raw_input("a"),b = raw_input("b"))

enter image description here

if we feed input are 1 and 2 then it will showing 12 instead of 3

Suever
  • 64,497
  • 14
  • 82
  • 101
siddhesh
  • 1
  • 1
  • 1

2 Answers2

0

raw_input returns a string and not a number. With string inputs, + simply concatenates the two strings together.

'1' + '2'
# '12'

If you want to perform numeric operations (such as addition), you need to first convert the output of raw_input to a number using int (for integers) or float (for floating point numbers).

sum_double(a = int(raw_input("a")),b = int(raw_input("b")))
Suever
  • 64,497
  • 14
  • 82
  • 101
0

raw_input returns a string ('1' and '2'). Summing them gives you '12'.

In order to sum numbers, not strings, convert the strings to numbers:

sum_double(a = int(raw_input("a")),b = int(raw_input("b")))
ForceBru
  • 43,482
  • 10
  • 63
  • 98