input: Write a function to train a Bernoulli Naive Bayes model for sentiment analysis and predict the sentiment of a given text.
  assert train_and_predict_sentiment('I love it when the weather is good.') == 'positive'
  assert train_and_predict_sentiment('This is the worst movie I have ever seen.') == 'negative'
  assert train_and_predict_sentiment('The food was amazing and the service was excellent.') == 'positive'
output: def train_and_predict_sentiment(text):
      from sklearn.feature_extraction.text import CountVectorizer
      from sklearn.naive_bayes import BernoulliNB
      from sklearn.pipeline import Pipeline
      import numpy as np
      
      # Training data
      train_texts = [
          'I love this product!',
          'This is the best day ever!',
          'I am so happy with the service.',
          'The movie was fantastic!',
          'This is the worst product I have ever bought.',
          'I hate this so much.',
          'This is terrible!',
          'I am very disappointed with the quality.'
      ]
      train_labels = ['positive', 'positive', 'positive', 'positive', 'negative', 'negative', 'negative', 'negative']
      
      # Create a pipeline that vectorizes the text and then applies the Naive Bayes classifier
      model = Pipeline([
          ('vectorizer', CountVectorizer(binary=True)),
          ('classifier', BernoulliNB())
      ])
      
      # Train the model
      model.fit(train_texts, train_labels)
      
      # Predict the sentiment of the given text
      predicted_label = model.predict([text])[0]
      
      return predicted_label