Let's write a program that asks the user for numbers, integers. Then it will compute the average of those numbers. It will also allow the user to enter negative one to quit the program and calculate the average. So I'm going to store my numbers in a list. Num list equals empty list. I'm going to count the numbers in that list so I can calculate the average later, initialize a count to zero, and I'm going to create a flag to indicate that the program is waiting for user input. Playing equals true. Then I'm going to set up a loop to repeatedly get user input of an integer. So while playing is true, enter the loop and get some user input. So we'll store this in num, input, enter an int. We're going to cast it to an int. Let's first test to see if that number is negative one. If it's negative one, we're going to exit the loop and calculate the average of all the numbers. So if the num is equal to negative 1, playing to false. That will force us to exit the loop on the next iteration. Otherwise, add the number, if it's not negative one, to our list of numbers. Num list append num, and then increment our count of numbers. I plus or equal to 1, add number to list of numbers. Test if number is negative one to quit the program. Once we exit the loop, we're going to calculate the average of all the numbers that were entered. Num sum. We'll first going to get the sum of the numbers. Num sum equals 0. For each number in Num list, add it to the sum; num sum plus or equal to num. This will get the sum of all entered numbers, then we're going to calculate the average, calculate the average. We'll store that in num average. That will be the sum divided by the count of numbers, i, and then we'll print it. Print average, num average. Let's run our code. Let's get the average of some numbers. Enter an int, three, enter an int, three, enter an int, three. I'm going to enter negative one to exit the program and calculate the average. Average, 2.0. So what's wrong with this program? I can see that even if we enter a negative one, we set playing to false, but we're still adding that negative one to our list of numbers. So it's being calculated as part of the average. So what we need to do is to account for this. If it is negative one, set playing to false. Else, add the number or append the number to our list, and then increment the count. Let's run our code. Enter an int 3, 3, 3, negative 1, average, 3. Let's run it again; 1, 2, 3, negative 1, average 2.