Here are the formulas I would use. I will leave it up to you to match them
with the notation in your textbook or notes, and to do the computation.
You have $k = 7$ values $v_1 = 0,\, v_2 = 1,\, \dots,\, v_7 = 6,$ and you have
$k$ corresponding frequencies $f_1 = 3,\, f_2 = 7,\, \dots,\, f_7 = 2.$
The total number of observations is $\sum_{i=1}^k f_i = 40.$ You say
you have found the sample mean $\bar X = \frac{1}{n} \sum_{i=1}^k f_iv_i = 2.45.$
(Your book might call the values $x_i$ instead of my $v_i.$)
Then the sample variance is
$$ S_X^2 = \frac{1}{n-1} \sum_{i-1}^k f_i(v_i - \bar X)^2.$$
You might want to make a table with columns headed
$i,\, f_i,\, v_i, v_i - \bar X,\, (v_i - \bar X)^2,$ and $f_i(v_i - \bar X)^2.$
(The body of the table will have seven rows.)
Then find the total of the last column and divide that total by $n-1 = 39.$
Note: This is a sample from some unknown discrete probability distribution. My best guess
is that the population distribution from which the data were randomly sampled
might be a Poisson distribution with mean approximately 2.45. But that is
only speculation. Samples from Poisson populations often have sample
means and variances that are numerically not far apart. My (unchecked!!) value for
the sample variance is a little above 2, so that encouraged me to mention
the Poisson idea. Maybe later in your course you will do a formal test
to see if the data are truly consistent with a Poisson population.
The sketch below shows your frequencies (bars) along with frequencies that
would be 'expected' if data were sampled from a Poisson distribution (red dots).
The fit does not look fantastic, but it is actually not bad for a sample
as small as $n = 40.$
