mercredi 15 juin 2016

Python For / IF loop not working

Im trying to make it so that if it finds a bluetooth devices with my adress it prints your care is save. But when my addr is not found it should display car is stolen. But now it prints its for every bluetooth devices it finds what not looks like my addr. I want to check if 2 adresses are found so yea its save with the rest it should display car has been stolen! Whats the best way to do this, I cant figure out how without printing care stolen everytime.

import bluetooth

def vindbluetooth():
    print("Searching for the car owner,,,,")

    nearby_devices = bluetooth.discover_devices(lookup_names=True)
    for addr, name in nearby_devices:
        if addr == "xx:xx:xx:xx:xx:34":
            print(addr)
            print("Owner Found: " + name + " Car is save!")

        elif not addr == "xx:xx:xx:xx:xx:34" :
            print("Your car is stolen!")
vindbluetooth()

Aucun commentaire:

Enregistrer un commentaire