Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
609 B
1
Indexable
Never
def find_next_term(sequence):
    if len(sequence) < 2:
        return None  # Sequence must have at least two terms.
    
    # Find the last two terms in the sequence.
    second_last = sequence[-2]
    last = sequence[-1]

    # Calculate the difference between the last two terms.
    difference = last - second_last

    # Calculate the next term by adding the difference to the last term.
    next_term = last + difference

    return next_term

# Example usage with your sequence:
sequence = [31, 28, 31, 29]
next_term = find_next_term(sequence)
print(f"The next term in the sequence is: {next_term}")