83.0k views
3 votes
Assume the user responds with a 4 for the first number and a 6 for the second number.

a number. ")
answerA=input("Enter
answerB=input("Enter
a second number. ")
numberA= int(answerA)
numberB= int(answerB)
result = numberA - numberB/2
print ("The result is", result)
What is the output?
I
The result is

User DannyB
by
7.8k points

1 Answer

5 votes

Answer:

1.0

Step-by-step explanation:

Even though both numbers are integers, numberB is divided by 2 using float division which results in a float

6/2 = 3.0 which is a float

When you execute 4 - 3.0, the integer 4 is converted to float.

So it becomes 4.0 - 3.0 = 1.0

not 1

On the other hand if it were numberA - numberB//2 then

the // indicates an integer division 6//2 = 3

So the result becomes 4 - 3 = 1

These are subtle differences

User Gerben Van Dijk
by
8.4k points