0

I am very new to the coding world and stuck on this issue.I am attempting to pass two numbers as inputs and join them together into a single string. The problem I am encountering is that my code performs an addition function rather than combining the numbers. my code is below with the results after.

import sys

number1 = int(sys.argv[1])
number2 = int(sys.argv[2])

newnumber = number1 + number2
print(newnumber)

Program Failed for Input: 123 456 Expected Output: 123456 Your Program Output: 579

Any suggestions?

cs95
  • 379,657
  • 97
  • 704
  • 746
  • Possible duplicate of [Which is the preferred way to concatenate a string in Python?](https://stackoverflow.com/questions/12169839/which-is-the-preferred-way-to-concatenate-a-string-in-python) – cs95 Nov 02 '17 at 13:36

1 Answers1

0

You are converting the input to int, so obvisouly Python will perform integer addition.

Don't convert the input to int. This way Python will perform string concatenation.

import sys

number1 = sys.argv[1]  # no conversion to int
number2 = sys.argv[2]  # no conversion to int

newnumber = number1 + number2
print(newnumber)
DeepSpace
  • 78,697
  • 11
  • 109
  • 154