User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

If20. On the numerical axis are three points: A, B, C. Determine which of the last two points (B or C) is closer to A, and display this point and its distance from point A.

Solution in Python 3:

import random

A,B,C = random.sample(range(-10, 10), 3)

print("Number A:", A)
print("Number B:", B)
print("Number C:", C)

AB = abs(A-B)
AC = abs(A-C)

print("Distance from A to B:",AB)
print("Distance from A to C:",AC)

if AB < AC:
print("В is closer to A")
elif AB > AC:
print("C is closer to A")
print("B and C are equidistant to A")