Creating GameObject by using List

Hello everyone. I am new to Unity and C#. Please help me. My question is that:
if I click Keypad1, the number of game objects should be 1, and only one game object should be drawn.
if I click Keypad2, the number of game objects should be 2, and only 2 game objects should be drawn and the previous game object should be removed.
And so on. I am using the bellow codes, but it is wrong. If I use this codes and If I click the keypad, unlimited game objects have been creating.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CreateObjects : MonoBehaviour
{
List gemList;
int n;

GameObject sphere;

void Update()
{
    gemList = new List<GameObject>();

    if (Input.GetKeyDown(KeyCode.Keypad1))
    {
        n = 1;
    }
   else if (Input.GetKeyDown(KeyCode.Keypad2))
    {
        n = 2;
    }
    else if (Input.GetKeyDown(KeyCode.Keypad3))
    {
        n = 3;
    }
    else if (Input.GetKeyDown(KeyCode.Keypad4))
    {
        n = 4;
    }
    else if (Input.GetKeyDown(KeyCode.Keypad5))
    {
        n = 4;
    }

    for (int i = 1; i <= n; i++)
    {
        sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        gemList.Add(sphere);
    }
}

}

Maybe do something like this, where there is some delay

 GameObject sphere;
 bool press = false; 

 void Update()
 {
     gemList = new List<GameObject>();
     if (Input.GetKeyDown(KeyCode.Keypad1))
     {
         n = 1;
         press = true;
     }
    else if (Input.GetKeyDown(KeyCode.Keypad2))
     {
         n = 2;
         press = true;
     }
     else if (Input.GetKeyDown(KeyCode.Keypad3))
     {
         n = 3;
         press = true;
     }
     else if (Input.GetKeyDown(KeyCode.Keypad4))
     {
         n = 4;
         press = true;
     }
     else if (Input.GetKeyDown(KeyCode.Keypad5))
     {
         n = 5;
         press = true;
     }

     if (press)
         return;

     for (int i = 1; i <= n; i++)
     {
         sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
         gemList.Add(sphere);
         Invoke(nameof(ResetPress), 0.5f);
     }
 }

 void ResetPress()
 {
      n = 0;
      press = false;
 }