{"id":2305,"date":"2026-11-09T13:10:56","date_gmt":"2026-11-09T13:10:56","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=2305"},"modified":"2026-11-10T16:44:39","modified_gmt":"2026-11-10T16:44:39","slug":"expected-value-tutorial","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/","title":{"rendered":"Expected Value"},"content":{"rendered":"<h1><strong><b>Expected Value: Definition, Formula and Worked Examples<\/b><\/strong><\/h1>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">You have not studied for a 200 question multiple choice test, so you guess option D on every question. How many will you get right? You do not need to sit the test to know. Each question has a one in four chance, so you expect 50 right answers. That number is an expected value.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Expected value is one of the most useful ideas in probability. It lets you weigh outcomes by how likely they are, and give a single answer to the question: what should I expect on average? Insurers use it to set prices, businesses use it to compare projects, and data scientists use it to build models and judge them.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">This tutorial explains what expected value is, the general formula, two worked examples with the answers, how it is used to make decisions, its main properties, and how to calculate it in Python. If you want to read about random variables and probability density first, you can use the links at the end.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">What is the Expected Value?<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The expected value of a random variable is its theoretical mean: the long run average of the results if you repeated the experiment again and again. It is written E(X).<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Think of it as the return you can expect from an action. Some outcomes give more and some give less, and the expected value weighs each by how likely it is.<\/p>\n<ul style=\"font-family: Arial,Helvetica,sans-serif; margin: 0 0 16px; padding-left: 24px; font-size: 17px; line-height: 1.7; color: #1f2937;\">\n<li style=\"margin: 0 0 8px;\">It is an average, not a promise for one trial.<\/li>\n<li style=\"margin: 0 0 8px;\">It does not have to be a value that X can take. The expected value of a fair die is 3.5, which no roll can show.<\/li>\n<li style=\"margin: 0 0 8px;\">It is not always the most likely value.<\/li>\n<\/ul>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Why do We Need the Expected Value?<\/h2>\n<ul style=\"font-family: Arial,Helvetica,sans-serif; margin: 0 0 16px; padding-left: 24px; font-size: 17px; line-height: 1.7; color: #1f2937;\">\n<li style=\"margin: 0 0 8px;\">Making decisions. You can compare options with different risks, by comparing their expected gains.<\/li>\n<li style=\"margin: 0 0 8px;\">Pricing. Insurance premiums, ticket prices and warranties rest on expected cost.<\/li>\n<li style=\"margin: 0 0 8px;\">Planning. Expected demand, expected defects and expected waiting time guide stock and staffing.<\/li>\n<li style=\"margin: 0 0 8px;\">Statistics and machine learning. The mean, the variance and many loss functions are expected values.<\/li>\n<\/ul>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Expected Value Formula<\/h2>\n<div style=\"margin: 16px 0 24px;\"><img decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/Expected_Value1-1.png\" alt=\"expected value formula\" \/><\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">For a discrete random variable that takes the values x1, x2 up to xk with probabilities p1, p2 up to pk:<\/p>\n<div style=\"margin: 0 0 16px; padding: 12px 16px; background: #f5f8fc; border-left: 4px solid #0f2a4a; border-radius: 4px; overflow-x: auto; font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.6; font-weight: bold; color: #0f2a4a;\">E(X) = x1 times p1 + x2 times p2 and so on, up to xk times pk<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">In words: multiply each value by its probability, and add them up.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The probabilities must add up to 1. The expected value is then a weighted average, where the weights are the probabilities.<\/p>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">A Special Case: Guessing on a Test<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">If each question has the same chance P of being right, and there are n questions, the number of right answers is a binomial variable, and its expected value is:<\/p>\n<div style=\"margin: 0 0 16px; padding: 12px 16px; background: #f5f8fc; border-left: 4px solid #0f2a4a; border-radius: 4px; overflow-x: auto; font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.6; font-weight: bold; color: #0f2a4a;\">E = P times n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">This is the formula that the live page shows. It is a special case of the general formula, and it only works for a count of identical trials.<\/p>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Variance<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The expected value tells you the centre, and the variance tells you the spread: Var(X) = E(X squared) minus (E(X)) squared.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Expected Value Example<\/h2>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Example 1: Guessing on a Multiple Choice Test<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The live page: a test has 200 questions with options A, B, C and D, and you guess D on all of them. What is the expected number of correct answers?<\/p>\n<ul style=\"font-family: Arial,Helvetica,sans-serif; margin: 0 0 16px; padding-left: 24px; font-size: 17px; line-height: 1.7; color: #1f2937;\">\n<li style=\"margin: 0 0 8px;\">P = 1 divided by 4 = 0.25 (the chance that one answer is right).<\/li>\n<li style=\"margin: 0 0 8px;\">n = 200.<\/li>\n<li style=\"margin: 0 0 8px;\">Expected value = 0.25 times 200 = 50.<\/li>\n<\/ul>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The live page uses n = 200 in the working, but one line says 20. With 20 questions, the expected number is 5. The right number is 50 for 200 questions.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">How far can a guesser stray from 50? The standard deviation is 6.12, so most guessers score between about 38 and 62. The chance of scoring 60 or more by pure guessing is 0.0625.<\/p>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Negative Marking<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Many exams take away marks for wrong answers, to remove the benefit of guessing. With plus 4 for a right answer and minus 1 for a wrong one, each guess is worth 0.25 times 4 + 0.75 times (minus 1) = 0.25 marks, so 200 guesses give 50 marks. With plus 1 for right and minus one third for wrong, a guess is worth exactly 0, so guessing has no expected gain. That is why this scheme is used.<\/p>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Example 2: Drawing a Card<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The live page: a stack has 10 cards. One is labelled 1, two are labelled 2, three are labelled 3 and four are labelled 4. You draw one at random. Let X be the value on the card. Find the expected value.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 760px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Expected value of the card drawn, with probabilities<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 160px;\" scope=\"col\">Value x<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Cards<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">P(X = x)<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">x times P(X = x)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">1<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">1<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">0.1<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">0.1<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">2<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">2<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">0.2<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">0.4<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">3<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">3<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">0.3<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">0.9<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">4<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">4<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">0.4<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">1.6<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Total<\/th>\n<td style=\"padding: 12px 16px; vertical-align: top;\">10<\/td>\n<td style=\"padding: 12px 16px; vertical-align: top;\">1.0<\/td>\n<td style=\"padding: 12px 16px; vertical-align: top;\">3.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"margin: 0 0 16px; padding: 12px 16px; background: #f5f8fc; border-left: 4px solid #0f2a4a; border-radius: 4px; overflow-x: auto; font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.6; font-weight: bold; color: #0f2a4a;\">E(X) = 0.1 + 0.4 + 0.9 + 1.6 = 3.0.<\/div>\n<div style=\"margin: 16px 0 24px;\"><img decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/expected_value_problem.jpg\" alt=\"expected value example, drawing a card from a stack of 10 cards\" \/><\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Meaning: the average value over many draws is 3. A simulation of 100,000 draws gave 3.001. The value 3 can be drawn, but this is chance, since the expected value does not have to be a possible value.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">For the variance: E(X squared) = 1 times 0.1 + 4 times 0.2 + 9 times 0.3 + 16 times 0.4 = 10, so Var(X) = 10 minus 3 squared = 1.<\/p>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Example 3: A Dice Game<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A game costs you 2 rupees to roll a die. If you roll a six, you win 12 rupees. Otherwise you win nothing, so you lose the 2 rupees. The numbers are made up.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 640px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Outcomes, probabilities and gains for the dice game<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 200px;\" scope=\"col\">Outcome<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Probability<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Gain<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Six<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">1 of 6<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Plus 12<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Not six<\/th>\n<td style=\"padding: 12px 16px; vertical-align: top;\">5 of 6<\/td>\n<td style=\"padding: 12px 16px; vertical-align: top;\">Minus 2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Expected gain = 12 times (1 divided by 6) + (minus 2) times (5 divided by 6) = 2 minus 1.667 = 0.333 rupees per game. The game favours you slightly. In my simulation of 100,000 games, the average gain was 0.306, close to 0.333.<\/p>\n<div style=\"position: relative; width: 100%; padding-bottom: 56.25%; height: 0; overflow: hidden; margin: 20px 0; border-radius: 8px; background: #0f2a4a;\"><iframe style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0;\" title=\"Expected value video\" src=\"https:\/\/www.youtube.com\/embed\/yyHNh_6luPc\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Properties of the Expected Value<\/h2>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 760px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Two properties of the expected value<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 420px;\" scope=\"col\">Property<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Meaning<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">E(aX + b) = a E(X) + b<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Scaling and shifting a variable scales and shifts its mean<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; vertical-align: top;\" scope=\"row\">E(X + Y) = E(X) + E(Y)<\/th>\n<td style=\"padding: 12px 16px; vertical-align: top;\">The mean of a sum is the sum of the means, even if X and Y are dependent<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">I checked both. For the card variable, E(X) = 3, so E(2X + 5) = 11. A simulation gave 11.006. Adding a die with a mean of 3.5, the mean of the sum is 6.5, and the simulation gave 6.5.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The second property is called linearity of expectation. It is the reason why the binomial mean is n times p: a binomial count is the sum of n trials, each with a mean of p.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Calculate Expected Value in Python<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">I ran the code below, and the output is real.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import numpy as np\r\nfrom scipy import stats\r\n\r\n# Page example 1: 200 four option questions, guess D on all\r\nn, p = 200, 0.25\r\nprint(\"Expected correct:\", n * p, \" sd:\", round(float((n * p * (1 - p)) ** 0.5), 3))\r\nprint(\"Typo case n = 20:\", 20 * p)\r\nprint(\"P(at least 60 correct by guessing):\", round(float(stats.binom.sf(59, n, p)), 4))\r\n# Negative marking: +4 for right, minus 1 for wrong\r\nprint(\"Expected marks, plus 4 right and minus 1 wrong:\", n * (p * 4 + (1 - p) * -1))\r\nprint(\"Expected marks, plus 1 right and minus one third wrong:\", round(n * (p * 1 + (1 - p) * (-1 \/ 3)), 3))\r\n\r\n# Page example 2: cards, one 1, two 2s, three 3s, four 4s\r\nvals = np.array([1, 2, 3, 4])\r\nprobs = np.array([1, 2, 3, 4]) \/ 10\r\nex = float((vals * probs).sum())\r\nex2 = float((vals ** 2 * probs).sum())\r\nprint(\"E(X):\", ex, \" E(X squared):\", ex2, \" Var(X):\", round(ex2 - ex ** 2, 3))\r\n\r\n# Simulation of the cards\r\nrng = np.random.default_rng(14)\r\ndeck = np.array([1, 2, 2, 3, 3, 3, 4, 4, 4, 4])\r\ndraws = rng.choice(deck, 100000)\r\nprint(\"Simulated mean of 100000 draws:\", round(float(draws.mean()), 3))\r\n\r\n# Fair die and a game: win 12 if six, lose 2 otherwise\r\nprint(\"Die E(X):\", (np.arange(1, 7)).mean())\r\nprint(\"Game with a cost: expected gain per roll:\", round(12 * (1 \/ 6) - 2 * (5 \/ 6), 3))\r\nrolls = rng.integers(1, 7, 100000)\r\ngain = np.where(rolls == 6, 12, -2)\r\nprint(\"Simulated average gain:\", round(float(gain.mean()), 3))\r\n\r\n# Linearity: E(aX + b) = a E(X) + b, and E(X + Y) = E(X) + E(Y)\r\nx = rng.choice(deck, 200000)\r\ny = rng.integers(1, 7, 200000)\r\nprint(\"E(2X + 5) theory:\", 2 * ex + 5, \" simulated:\", round(float((2 * x + 5).mean()), 3))\r\nprint(\"E(X + Y) theory:\", ex + 3.5, \" simulated:\", round(float((x + y).mean()), 3))<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">Expected correct: 50.0  sd: 6.124\r\nTypo case n = 20: 5.0\r\nP(at least 60 correct by guessing): 0.0625\r\nExpected marks, plus 4 right and minus 1 wrong: 50.0\r\nExpected marks, plus 1 right and minus one third wrong: 0.0\r\nE(X): 3.0  E(X squared): 10.0  Var(X): 1.0\r\nSimulated mean of 100000 draws: 3.001\r\nDie E(X): 3.5\r\nGame with a cost: expected gain per roll: 0.333\r\nSimulated average gain: 0.306\r\nE(2X + 5) theory: 11.0  simulated: 11.006\r\nE(X + Y) theory: 6.5  simulated: 6.5<\/pre>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Common Mistakes to Avoid<\/h2>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 760px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Common mistakes and fixes<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 420px;\" scope=\"col\">Mistake<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Using the wrong n in P times n<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Use the number of questions in the test, and check it throughout<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Treating the expected value as the most likely value<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">It is a long run average<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Thinking it must be a possible outcome<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">A die has an expected value of 3.5<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Forgetting that probabilities must add to 1<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Check the total<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Using the simple average of the values<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Weight each value by its probability<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Ignoring negative payoffs<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Losses count as negative values<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Using the guessing formula for non identical trials<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Use the general formula<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Spelling it Expect Value<\/th>\n<td style=\"padding: 12px 16px; vertical-align: top;\">It is Expected Value<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Practice Questions<\/h2>\n<ol style=\"font-family: Arial,Helvetica,sans-serif; margin: 0 0 16px; padding-left: 28px; font-size: 17px; line-height: 1.7; color: #1f2937;\">\n<li style=\"margin: 0 0 8px;\">A test has 80 questions with 5 options each. What is the expected number of right answers if you guess?<\/li>\n<li style=\"margin: 0 0 8px;\">A die is rolled. What is the expected value?<\/li>\n<li style=\"margin: 0 0 8px;\">A game pays 5 rupees with a probability of 0.2 and 0 otherwise. What is the expected payoff?<\/li>\n<li style=\"margin: 0 0 8px;\">If E(X) = 4, what is E(3X + 2)?<\/li>\n<\/ol>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Answers: 1) P = 0.2, so 0.2 times 80 = 16. 2) (1 + 2 + 3 + 4 + 5 + 6) divided by 6 = 3.5. 3) 5 times 0.2 = 1 rupee. 4) 3 times 4 + 2 = 14. These are my own answers, so please recheck them before publishing.<\/p>\n<p>Expected value turns uncertainty into one honest number: the average you should plan for. Multiply each outcome by its chance, add them up, and remember that it is a long run average, not a promise for the next trial.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Expected Value: Definition, Formula and Worked Examples You have not studied for a 200 question multiple choice test, so you guess option D on every question. How many will you get right? You do not need to sit the test to know. Each question has a one in four chance, so you expect 50 right [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,1704],"tags":[155,153,156,152,161],"class_list":["post-2305","post","type-post","status-publish","format-standard","hentry","category-data-science","category-data-science-modules","tag-expected-value-example","tag-expected-value-formula","tag-expected-value-in-data-science","tag-expected-value-tutorial","tag-how-to-calculate-expected-value"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Expected Value Tutorial: Definition, Formula and Examples<\/title>\n<meta name=\"description\" content=\"Learn expected value: definition, general formula, worked examples with the answers, properties, dice and test guessing, and Python code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Expected Value Tutorial: Definition, Formula and Examples\" \/>\n<meta property=\"og:description\" content=\"Learn expected value: definition, general formula, worked examples with the answers, properties, dice and test guessing, and Python code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-09T13:10:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-10T16:44:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/Expected_Value1-1.png\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/\",\"url\":\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/\",\"name\":\"Expected Value Tutorial: Definition, Formula and Examples\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/Expected_Value1-1.png\",\"datePublished\":\"2026-11-09T13:10:56+00:00\",\"dateModified\":\"2026-11-10T16:44:39+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Learn expected value: definition, general formula, worked examples with the answers, properties, dice and test guessing, and Python code.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/Expected_Value1-1.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/Expected_Value1-1.png\",\"width\":209,\"height\":81},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Expected Value\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Expected Value Tutorial: Definition, Formula and Examples","description":"Learn expected value: definition, general formula, worked examples with the answers, properties, dice and test guessing, and Python code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Expected Value Tutorial: Definition, Formula and Examples","og_description":"Learn expected value: definition, general formula, worked examples with the answers, properties, dice and test guessing, and Python code.","og_url":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2026-11-09T13:10:56+00:00","article_modified_time":"2026-11-10T16:44:39+00:00","og_image":[{"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/Expected_Value1-1.png","type":"","width":"","height":""}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/","url":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/","name":"Expected Value Tutorial: Definition, Formula and Examples","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/Expected_Value1-1.png","datePublished":"2026-11-09T13:10:56+00:00","dateModified":"2026-11-10T16:44:39+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Learn expected value: definition, general formula, worked examples with the answers, properties, dice and test guessing, and Python code.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/Expected_Value1-1.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/06\/Expected_Value1-1.png","width":209,"height":81},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/data-science\/data-science-modules\/expected-value-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Expected Value"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=2305"}],"version-history":[{"count":15,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2305\/revisions"}],"predecessor-version":[{"id":12166,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2305\/revisions\/12166"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=2305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=2305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=2305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}