How to add two numbers from input()

Modify the following code snippet to add two numbers.
For example:
Test Input Result
get_input() 12 Enter number one: 12
23 Enter number two: 23
Answer:(penalty regime: 0 %)

please helps me how done this code

def get_input():
# Only edit the code segment between the dashes

# ------------------------------------

a = input("Enter number one:12 ")
b = input("Enter number two:23 ")

# ------------------------------------

print (a+b)

It seems to me that the concept here is to teach you that the input() function returns a string object, by default. So if you want to add numbers, then you need to type convert the input.

If you run the code as is (and enter 12 and 23) you’ll get 1223, because the function is doing something called ‘sting concatenation’: 12+23 = 1223

There a a few ways to do type conversions, the most common is to do said ‘on-the-fly’:
a = int(input("Enter number one: "))
b = int(input("Enter number two: "))

1 Like

thank your so much sir

1 Like

Do note that your example code assumes the input numbers are integers, whereas that is not stated anywhere in the problem. If the user does enter a non-integer for either number, the code will immediately fail with an error. Therefore, I would suggest using float() instead of int() to avoid this issue.

1 Like

Thank you. My assumption was based upon:

… which to me, suggests that integers are called for, if not literally 12 and 23 but, in my experience, I have to say that it’s a strange way to prompt for integer values.

1 Like

I assumed that was a mistake/accident, e.g. the user or instructor had mistakenly entered those numbers there in the prompt.

In any case, whichever was intended, the question should have been clear on this point.

1 Like

Possibly, it’s a code generated question/answer system and the ‘code’ for said has some bug that has inserted the values, rather than using those values to check for a correct answer – just a thought.

uh it didnt work for me apparently…why is that???

can you copy paste the full code as a reply to me please dude?