input: 
  import tensorflow as tf
  
  # Import MNIST data
  from tensorflow.examples.tutorials.mnist import input_data
  mnist = input_data.read_data_sets("/tmp/data", one_hot=True)
  
  # Train model
  model = tf.Session()
  model.run(init)
  
  # Training cycle
  for epoch in range(training_epochs):
      avg_cost = 0.
      total_batch = int(mnist.train.num_examples/batch_size)
      # Loop over all batches
      for i in range(total_batch):
          batch_x, batch_y = mnist.train.next_batch(batch_size)
          # Run optimization op (backprop) and cost op (to get loss value)
          _, c = model.run([train_op, loss_op], feed_dict={X: batch_x,
                                                          Y: batch_y})
          # Compute average loss
          avg_cost += c / total_batch
      # Display logs per epoch step
      if epoch % display_step == 0:
          print("Epoch:", '%04d' % (epoch+1), "cost=", \
              "{:.9f}".format(avg_cost))
  print("Optimization Finished!")
  
  # Test model
  pred = tf.nn.softmax(logits)  # Apply softmax to logits
  correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(Y, 1))
  # Calculate accuracy
  accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
  print("Accuracy:", accuracy.eval({X: mnist.test.images, Y: mnist.test.labels}, model))
  
  
  Question: Can you explain how does the provided code train a neural network model using TensorFlow and Python for classifying hand-written digits from the MNIST dataset? Specifically, how does the training loop work, and how is the accuracy of the model evaluated after training?
output:     # Define placeholders for inputs to network
      X = tf.placeholder(tf.float32, [None, 784])
      Y = tf.placeholder(tf.float32, [None, 10])
  
      # Set model weights
      W = tf.Variable(tf.zeros([784, 10]))
      b = tf.Variable(tf.zeros([10]))
  
      # Construct model
      logits = tf.matmul(X, W) + b
  
      # Define loss and optimizer
      loss_op = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(
          logits=logits, labels=Y))
      optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate)
      train_op = optimizer.minimize(loss_op)
  
      # Initialize the variables (i.e. assign their default value)
      init = tf.global_variables_initializer()
  
      # Start training
      model.run(init)
  
      # Training cycle
      for epoch in range(training_epochs):
          avg_cost = 0.
          total_batch = int(mnist.train.num_examples/batch_size)
          # Loop over all batches
          for i in range(total_batch):
              batch_x, batch_y = mnist.train.next_batch(batch_size)
              # Run optimization op (backprop) and cost op (to get loss value)
              _, c = model.run([train_op, loss_op], feed_dict={X: batch_x,
                                                              Y: batch_y})
              # Compute average loss
              avg_cost += c / total_batch
          # Display logs per epoch step
          if epoch % display_step == 0:
              print("Epoch:", '%04d' % (epoch+1), "cost=", \
                  "{:.9f}".format(avg_cost))
      print("Optimization Finished!")
  
      # Test model
      pred = tf.nn.softmax(logits)  # Apply softmax to logits
      correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(Y, 1))
      # Calculate accuracy
      accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
      print("Accuracy:", accuracy.eval({X: mnist.test.images, Y: mnist.test.labels}, model))