Я хочу иметь возможность использовать переменную BestELevator вне функции findElevator (In python)
userPosition = int(input('Enter the position of the user: '))
userDirection = str(input('Enter the direction floor (up/down): '))
elevatorList = {
1: {'position':'6', 'direction':'down', 'status':'move', 'gap':'', 'priority':''} ,
2: {'position':'-6', 'direction':'up' , 'status':'idle', 'gap':'', 'priority':''}
}
def findElevator(userPosition, userDirection):
for i in elevatorList:
elevatorPosition = int(elevatorList[i]['position'])
elevatorDirection = str(elevatorList[i]['direction'])
if (elevatorPosition == userPosition) & (elevatorDirection == userDirection):
elevatorList[i]['priority'] = 55
bestElevator = elevatorList[i]
return bestElevator
else:
print('doesnt work ')
findElevator(userPosition, userDirection)
print(bestElevator)