-1

The code below is giving me a return of 25 with inputs of 3 & 4. Obviously it should be 7. This is a problem for school and I can't edit the first 3 lines or the last one. What am I missing here?

total_owls = 0
num_owls_A = input()
num_owls_B = input()
num_owls_A = int(input())
num_owls_B = int(input())
total_owls = (num_owls_A + num_owls_B)
print('Number of owls:', total_owls)

1 Answers1

2

input() returns input value as a string. So, you are basically concatenating strings not integers.

If you want to add them as numbers you need to convert them to numbers first like below

num_owls_A = int(input())
num_owls_B = int(input())

Again, this will create an error, if you input a non-numerical value, so you need to handle the exceptions in such case.

Kris
  • 8,680
  • 4
  • 39
  • 67