[SOLVED] HELP Clumsy Circle

This is my code, it works fine but my soldier says random id

# Find the soldiers who break the circle.

# All soldiers should be on the circle with the radius:
circleRadius = 20

# The function checks if an unit is placed on the circle
# with the radius with the hero in the center.
def onCircle(unit, radius):
    distance = hero.distanceTo(unit)
    # We check the approximation.
    inaccuracy = 2
    minDistance = radius - inaccuracy
    maxDistance = radius + inaccuracy
    return distance <= maxDistance and distance >= minDistance

while True:
    soldiers = hero.findByType("soldier")
    for soldier in soldiers:
        # Use onCircle function to find
        # if the soldier is not on the circle:
        if onCircle(soldier, circleRadius):
            # Then say their name (`id`) to get rid of that one:
            hero.say(soldier.id)
        pass

Take a closer look at the comment:

        # if the soldier is **not** on the circle:

but how do i code that
i tried

if onCircle(soldier, circleRadius) false:

but it gives me this error:

It’s because your syntax is a bit off. Your new code is close, but a better way to test for a ‘false’ result is to use ‘not’. For example:

a = 1
b = 1
if a == b: # which is true in this case
    hero.say(soldier.id)

or to test for a false return:

a = 0
b = 1
if not(a == b): # a does not equal b so the comparison returns false
    # using the not parameter is testing to see if (a == b) is false, if it is,
    # then the entire statement is true, so the hero speaks
    hero.say(soldier.id)

Thanks just solved it!

1 Like