Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Metal Detector - Help Needed - Solved

Write the function.

def coinDistance():
# Find the nearest coin,
item = hero.findNearestItem()

# If there is a coin, return the distance to it.
if item:
    return item
    
# Else, return 0 (zero).
else:
    
    return 0
pass

while True:
distance = coinDistance()
if distance > 0:
# Say the distance.
hero.say(distance)
pass


# Write the function.
def coinDistance():
    # Find the nearest coin,
    item = hero.findNearestItem()
    
    
    # If there is a coin, return the distance to it.
    if item:
        return item
        
    # Else, return 0 (zero).
    else:
        
        return 0
    pass

while True:
    distance = coinDistance()
    if distance > 0:
        # Say the `distance`.
        hero.say(distance)
        pass

I got the answer. sorry

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.