gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
Given a list of non-zero integers, find and print the first adjacent pair of elements…
- User
Given a list of non-zero integers, find and print the first adjacent pair of elements that have the same sign. If there is no such pair, print 0.
Example input #1 -1 2 3 -1 -2 Example output #1 2 3 Example input #2 1 -3 4 -2 1 Example output #2 0
- Assistant
Here is a code to implement this task:
pythondef find_adjacent_same_sign(numbers): for i in range(len(numbers) - 1): if numbers[i] * numbers[i + 1] > 0: return numbers[i], numbers[i + 1] return 0, 0 # Example usage input1 = [-1, 2, 3, -1, -2] print(find_adjacent_same_sign(input1)) # Output: (2, 3) input2 = [1, -3, 4, -2, 1] print(find_adjacent_same_sign(input2)) # Output: (0, 0)You can use the function
find_adjacent_same_sign()with any list of non-zero integers.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.