# Average

**Q1.** Enter and run this code:

**1 #Calculate the average**2

**3 sum = 0.0**

4

**5 print ("Calculate the average of some numbers.")**

**6 count = int(input("How many numbers will you enter: "))**

**7 current_number = 1**

8

**9 while current_number < count+1:**

**10 print ("\nNumber",current_number, end=" ")**

**11 number = float(input("\tEnter a number: "))**

**12 sum = sum + number**

**13 current_number = current_number + 1**

**14**

15 print("\n\nThe average was:",sum/count)

15 print("\n\nThe average was:",sum/count)

**Q2. **Describe how this program works, step by step.**Q3. **On what lines do initialisation occur? What is meant by initialisation?

**Why should variables be initialised?**

Q4.

Q4.

**Describe the ways that this program has been written so it is as easy as possible to understand.**

Q5.

Q5.

**Explain the purpose of end=" " on line 10.**

Q6.

Q6.

**Rewrite line 13 using +=**

Q7.Q7.

**In the above program, you have to enter how many numbers you want to average. Your task is to write a program that lets any number of numbers be entered, until the user says they have finished. The pseudo-code for one solution is as follows:**

Q8.Q8.

**Comment what the program is aboutInitialise sum = 0.0Initialise count = 0Initialise enter_number to "y"**

**print titlewhile enter_number = y print "number", count+1 input a number sum = sum + number count = count + 1 display message; 'Y' for another number or any other key to quit.print "The average is sum/countdisplay 'Press enter to quit'**

Turn the above pseudo-code into Python code and run and test it. If you enter these numbers to find the average: 5, 10 and 2, the answer is 5.666666666666667

Q9.

How can you round this down to two decimal places?

**Can you make any improvements to this program, perhaps in the way it is laid out or functions?**

Q10.Q10.