input: Write a python function to create and compile a Sequential model using Keras with Conv2D and Dense layers, and train it on the MNIST dataset.
  assert isinstance(model, Sequential)
  assert model.layers[0].__class__.__name__ == 'Conv2D'
  assert model.layers[-1].__class__.__name__ == 'Dense'
output: def create_and_train_model():
      import tensorflow as tf
      from tensorflow.keras.datasets import mnist
      from tensorflow.keras.models import Sequential
      from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
      from tensorflow.keras.utils import to_categorical
  
      # Load and preprocess the MNIST dataset
      (x_train, y_train), (x_test, y_test) = mnist.load_data()
      x_train = x_train.reshape(-1, 28, 28, 1).astype('float32') / 255
      x_test = x_test.reshape(-1, 28, 28, 1).astype('float32') / 255
      y_train = to_categorical(y_train, 10)
      y_test = to_categorical(y_test, 10)
  
      # Create the Sequential model
      model = Sequential([
          Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 1)),
          MaxPooling2D(pool_size=(2, 2)),
          Flatten(),
          Dense(128, activation='relu'),
          Dense(10, activation='softmax')
      ])
  
      # Compile the model
      model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
  
      # Train the model
      model.fit(x_train, y_train, epochs=5, batch_size=32, validation_data=(x_test, y_test))
  
      return model