fork download
  1. def find_port(ports, target):
  2. """
  3. Returns the first integer in ports that equals the target or is greater.
  4. If there is no solution, returns -1.
  5.  
  6. Args:
  7. ports (list): [80, 22, 443, 21]
  8. target (int): 25
  9. print(find_port(ports, target))
  10.  
  11. Returns:
  12. int: The first port number greater than or equal to the target, or -1 if not found.
  13. """
  14. # Iterate over the ports and return the first one that's greater than or equal to the target
  15. for port in ports:
  16. if port >= target:
  17. return port
  18.  
  19. # If no port is greater than or equal to the target, return -1
  20. return -1
Success #stdin #stdout 0.12s 14144KB
stdin
Standard input is empty
stdout
Standard output is empty