Term pack
Class 8 Computer Science
Name: ________________________
Skills in this pack
- Hexadecimal numbers
- Text as numbers
- The boxes that make a network work
- The shapes a network is built in
- Addresses and names on a network
- Spreadsheet functions
- Copying formulas, and references that stay put
- Charts from a spreadsheet
- Loops that count
- Blocks and indentation
- Loops inside loops
- Procedures, and calling them
- Procedures that take values and give one back
Free at www.arenapublications.com/learn — no account, no ads, ever.
Class 8 Computer Science · 1 of 13
Hexadecimal numbers
Read a hexadecimal number, turn it into decimal or into binary, and say why programmers write bits this way.
1.Two hexadecimal digits are written side by side. What is the largest decimal number the pair of them can hold between them?
- a) 255
- b) 256
- c) 99
- d) 128
2.Write the decimal number 45 in hexadecimal. Use two hexadecimal digits.
3.Which point on the line is the hexadecimal number 3A written in decimal?
Mark the line with an X.
4.Put these hexadecimal numbers in order, smallest first.
- 1F
- FF
- 4D
- 2A
- B0
5.Write the hexadecimal number A7 as eight binary bits.
6.Write the decimal number 200 in hexadecimal. Use two hexadecimal digits.
7.Match each hexadecimal digit to the four bits it stands for.
- 4
- 7
- 9
- D
- E
- 1110
- 0100
- 1001
- 1101
- 0111
8.The binary number 11010110 is split down the middle into two groups of four bits. Write those eight bits as two hexadecimal digits.
Hexadecimal numbers · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 2 of 13
Text as numbers
Work out the code number a character is stored as, and how many bytes a piece of text needs.
1.Small a is stored as 97 and the small letters carry straight on from there. What number is stored for small f?
2.Capital A is stored as 65 and small a is stored as 97. How much bigger is the code for a small letter than the code for the capital of the very same letter?
3.Capital A is stored as 65 and the capital letters carry straight on from there. Which capital letter is stored as 72?
4.In a computer's character code, capital A is stored as 65 and the capital letters that follow carry straight on. What number is stored for capital D?
5.Digit characters run in order from 48, capitals from 65 and small letters from 97. Put these characters in order of the code number stored for each, smallest first.
- the digit character 7
- capital B
- small z
- capital M
- small d
6.The capital letters run in order from 65 and the small letters run in order from 97, twenty-six of each. Sort each code number by which kind of letter it stands for.
Groups: A capital letter · A small letter
- 78
- 115
- 99
- 70
- 104
- 88
7.Each message is stored one character per byte, gaps included. Match each message to the number of bytes it needs.
- YES
- HELLO
- OK NOW
- GOODBYE
- I AM HERE
- 6
- 9
- 7
- 5
- 3
8.A message is stored with two bytes for every character. How many bytes does the word MOON need?
Text as numbers · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 3 of 13
The boxes that make a network work
Work out what a hub, a switch, a router, a modem and an access point each do, and choose the one a job needs.
1.Two computers stand in the same room and are plugged into the same switch. One sends the other a file. Does the file pass through the router at the edge of the building?
- a) No — both machines are on the same network, so the switch can deliver it by itself
- b) Yes — every message a computer sends passes through the router
- c) No — a message between two computers uses no device at all
- d) Yes, because the router holds the list of which machine is which
2.A hub copies every message out to every other machine plugged into it. Four computers are on one hub, and each of the four sends one message. How many copies arrive at machines altogether?
3.A school has two buildings, and each building has a network of its own. Messages now need to travel between the two. Which device does that job?
- a) A router
- b) A longer cable and nothing else
- c) A switch
- d) A hub
4.A switch sends a message out to the one machine it is addressed to and to nobody else. Eight computers are plugged into a switch, and one sends a message meant for a second. How many computers receive a copy of it?
5.Ten computers are plugged into one hub, which copies every message out to every other machine. The hub is swapped for a switch, which sends a message only to the machine it is addressed to. One computer now sends one message. How many fewer copies leave the device than before?
6.A lab already has a switch with every computer cabled to it. An access point is added. What can the lab do now that it could not do before?
- a) Reach a second network on the other side of the school
- b) Push messages along the existing cables faster than before
- c) Stop a copy of every message going to every machine
- d) Let a device with no cable of its own join the network
7.A hub copies every message it receives out to every other machine plugged into it. Eight computers are plugged into one hub, and one of them sends a message meant for a second. How many computers receive a copy of it?
8.A lab with twenty machines has its hub taken out and a switch put in its place, and everything suddenly runs faster. What is the reason?
- a) Far fewer copies of each message are being put on the cables, so there is less traffic to get through
- b) A switch is built with thicker cables than a hub is
- c) A switch sits closer to the machines than a hub does
- d) A switch keeps a copy of every message so nothing ever needs sending twice
The boxes that make a network work · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 4 of 13
The shapes a network is built in
Work out how much cable a bus, star, ring or mesh needs, and what a single break costs each of them.
1.In a mesh every computer has a cable to every other one. Match each mesh to the number of cables it needs.
- 3 computers
- 8 computers
- 9 computers
- 10 computers
- 12 computers
- 28
- 3
- 66
- 36
- 45
2.In a mesh, every computer has a cable to every other one. How many cables run from one single computer in a mesh of seven?
3.Six computers are joined in a star. Each one has a single cable running to the switch in the middle, and no other cables at all. How many cables does the network use?
4.In a star network each computer has one cable of its own to the switch in the middle. One of those outer cables is cut. What happens?
- a) The switch is cut off but the computers can still reach each other
- b) Every computer on the network is cut off from every other one
- c) The computer on the far end of that cable is cut off, and the rest carry on as before
- d) Nothing changes at all, because messages take a different route
5.Put these networks in order by how many cables each one uses, fewest first.
- A bus joining four computers along one long cable
- A star joining four computers to a switch
- A mesh joining five computers
- A mesh joining four computers
6.Five computers are joined in a mesh, so every computer has its own cable to every other computer. How many cables is that altogether?
7.A full mesh is almost never used for a large office. What is the reason?
- a) The number of cables climbs far faster than the number of computers does
- b) No more than four computers can ever be joined in a mesh
- c) A mesh can only carry a message in one direction round the office
- d) A mesh stops working the moment a single cable is cut
8.A star has eight computers around one switch. The switch itself stops working. How many of the eight can still reach another computer?
The shapes a network is built in · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 5 of 13
Addresses and names on a network
Read a machine's address, work out which machines share a network, and say what turns a name into an address.
1.Every address on one network begins 10.4.2, and the last number may be anything from 20 to 90. How many machines can that network hold?
2.Which of these is a name service's job rather than a router's?
- a) Joining two different networks together
- b) Choosing which network to hand a message on to next
- c) Carrying a message out of the building
- d) Saying which number belongs to a given name
3.Machines share a network when the first three of their four numbers match. Of the four numbers, which single one is the only thing telling two machines on one network apart? Answer with an ordinal such as second or third.
4.Someone types a name into a browser and the browser has never met that name before. Put these four things in the order they happen.
- The name service answers with the number
- The browser sends its request to that number
- The browser asks a name service which number goes with that name
- The browser is handed a name
5.Two different machines on one network are given the same address by mistake. What goes wrong?
- a) Both machines stop working altogether until one is unplugged
- b) Messages meant for one of them can arrive at the other, because the address no longer says which machine is which
- c) Nothing goes wrong, because an address is allowed to be shared
- d) The network runs more slowly, but everything still arrives where it should
6.An address is four numbers, and each of the four is held in one byte. How many bits long is a whole address?
7.A website is moved onto a different machine with a different address, and keeps the name it always had. What has to be changed so that people can still reach it?
- a) The address of the computer belonging to each person visiting
- b) The name itself, so that it matches the new machine
- c) What the name service answers when it is asked about that name
- d) Every browser in the world, one at a time
8.A machine's address is four numbers separated by dots, and every one of the four runs from 0 to 255. Which of these could never be a machine's address?
- a) 100.200.50.25
- b) 172.16.254.9
- c) 10.0.0.1
- d) 192.168.0.300
Addresses and names on a network · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 6 of 13
Spreadsheet functions
Work out what SUM, AVERAGE, MAX, MIN, COUNT and IF show for a sheet you are given.
1.A sheet holds M1 = 9, M2 = 4, M3 = 15 and M4 = 4. Sort each formula by whether it shows 15.
Groups: Shows 15 · Shows something else
- =SUM(M1:M2)+2
- =MAX(M1:M4)
- =COUNT(M1:M4)
- =M3
- =MIN(M1:M4)
- =SUM(M2:M4)
2.A sheet holds H1 = 60. This formula is typed into H2. What does H2 show?
=IF(H1 >= 60, "Full marks", "Not yet")
3.A sheet holds G1 = 72. This formula is typed into G2. What does G2 show?
=IF(G1 > 50, "Pass", "Try again")
4.A column of twelve cells holds nine numbers and three pieces of writing. What does a COUNT over the whole column show?
- a) 12
- b) 0
- c) 3
- d) 9
5.A sheet holds B2 = 6, B3 = 11, B4 = 4 and B5 = 9. What number does this formula show?
=AVERAGE(B2:B5)
6.A sheet holds S1 = 30. This formula is typed into S2. What does S2 show?
=IF(S1 > 30, "Over", "Not over")
7.A sheet holds Q1 = 3, Q2 = 12, Q3 = 6 and Q4 = 9. Put these formulas in order of the number each one shows, smallest first.
- =AVERAGE(Q1:Q4)
- =SUM(Q1:Q4)
- =COUNT(Q1:Q4)
- =MAX(Q1:Q4)
- =MIN(Q1:Q4)
8.A sheet holds D1 = 12, D2 = 45, D3 = 7 and D4 = 31. What number does this formula show?
=MIN(D1:D4)
Spreadsheet functions · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 7 of 13
Copying formulas, and references that stay put
Work out what a formula points at once it has been copied, and use a dollar sign to stop a reference moving.
1.Cell L1 holds 80. Cell L2 holds =L1/2, and that formula is copied down into L3, L4 and L5. Put these cells in order of the value each one shows, smallest first.
- L3
- L4
- L2
- L5
2.Cell A2 holds =A1+B1. The formula is copied into C5, so it has moved both across and down. In the copy, which cell takes the place of A1?
3.A dollar sign fixes the part of a reference it stands in front of. Cell G4 holds =$G$1+G3, and is copied down into G5. In the copy, which cell is added to $G$1?
4.Cell M10 holds =M9-$A$1. The formula is copied upwards into M4. In the copy, which cell has $A$1 taken away from it?
5.Cell E2 holds =E1+5. The formula is copied across into F2. Which cell does the copy add 5 to?
6.Cell N3 holds =SUM(N1:N2). The formula is copied down into N5. In the copy, which cell is the last one in the range being added up?
7.A dollar sign fixes the part of a reference it stands in front of. Cell H2 holds =H1*$B$1, and is copied across into I2. In the copy, which cell is $B$1 multiplied by?
8.A times-table grid is being built. Column A holds the numbers going down and row 1 holds the numbers going across. One formula is written in B2 and then copied both across and down to fill the whole grid. Which formula belongs in B2?
- a) =$A2*B$1
- b) =$A$2*$B$1
- c) =A$2*$B1
- d) =A2*B1
Copying formulas, and references that stay put · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 8 of 13
Charts from a spreadsheet
Choose the kind of chart a set of numbers needs, and read amounts and shares off the chart that results.
1.Someone draws a pie chart from the temperature at noon on each of four days. Why is a pie chart the wrong choice here?
- a) A pie chart cannot show a number larger than a hundred
- b) A pie chart can only ever show three things at a time
- c) The four days would have to be put in order of temperature first
- d) A slice shows a share of one whole, and four temperatures added together make no whole of anything
2.This bar chart has one bar for each of four shops. Tap the bar belonging to the shop that sold the second most.
Write the number of the part.
3.A sheet records how many of the 200 pupils in a year group joined each of four clubs, and every pupil joined exactly one. The chart is to show what share of the year group each club took. Which kind of chart is that?
- a) A line chart
- b) A chart with a single bar for the whole year group
- c) A chart with one point for each of the 200 pupils
- d) A pie chart
4.A bar chart's upright scale begins at 90 rather than at nothing. Two of its bars stand for 95 and for 100. What does the chart do to the difference between the two?
- a) Shows it exactly as it is
- b) Hides it, so that the two bars look identical
- c) Makes it look far bigger than it is
- d) Makes it look far smaller than it is
5.A chart is drawn from the range B2:B9, with one bar for each cell in it. How many bars does the chart have?
6.A pie chart is drawn for 24 people, one of whom is you. How many degrees of the circle does a single person take?
7.A bar chart is drawn from the range D2:D13, one bar for each cell. Two of those cells have been left empty and no bar is drawn for them. How many bars does the chart have?
8.A pie chart is drawn for four clubs that 200 pupils divided themselves between, and 50 of them joined one particular club. How many degrees of the circle does that club's slice take?
Charts from a spreadsheet · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 9 of 13
Loops that count
Work out what values a counting loop's variable takes, and how many times its body runs.
1.Each of these loops prints its counter every time round. Match each range to the last number the loop prints.
- range(1, 6)
- range(4, 9)
- range(0, 3)
- range(7, 11)
- range(2, 15)
- 2
- 8
- 5
- 14
- 10
2.Follow this code by hand. What is product at the end?
product = 1 for n in range(1, 5): product = product * n3.Look hard at the two numbers in the range. How many times does the indented line run?
for step in range(5, 5): print(step)- a) 1
- b) 10
- c) 0
- d) 5
4.Follow this code by hand. How many numbers does it print altogether?
for n in range(2, 7): print(n) print(n * 10)5.Sort each of these loop headings by how many times the body underneath it would run.
Groups: Three times · Four times
- for n in range(7, 10):
- for n in range(0, 4):
- for n in range(5, 8):
- for n in range(2, 6):
- for n in range(1, 4):
- for n in range(10, 14):
6.The counter starts a long way above zero here. How many times does the indented line run?
for n in range(10, 20): print(n * 2)7.This loop takes away rather than adds. What is total at the end?
total = 100 for n in range(1, 4): total = total - n8.A running total climbs inside this loop. What is total at the end?
total = 0 for n in range(1, 5): total = total + n
Loops that count · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 10 of 13
Blocks and indentation
Read a program's indentation to say which lines belong to which block, and how often each line runs.
1.Sort each line of this program by how many times it runs.
total = 0 for n in range(1, 4): total = total + n print(n) print(total) print(total * 2)Groups: Runs once · Runs three times
- total = 0
- print(n)
- print(total * 2)
- total = total + n
- print(total)
2.This program prints four numbers. Put them in the order they appear on the screen.
total = 0 for n in range(1, 4): total = total + 5 print(total) print(total - 12)- 10
- 15
- 3
- 5
3.This one has an else branch as well. What is total at the end?
total = 0 for n in range(1, 5): if n > 2: total = total + 1 else: total = total + 1004.This program was meant to show the total once, at the very end, but it shows a number four times over. What went wrong?
total = 0 for n in range(1, 5): total = total + n print(total)- a) The printing line is indented, so it sits inside the loop and runs every trip round
- b) The loop has been written to go round one time too many
- c) The total is set to 0 on the wrong line of the program
- d) A program is only allowed to print one number in total
5.Both of the printing lines are indented here. How many numbers does it print?
for n in range(1, 4): print(n) print(99)6.The last line has been brought back out to the left. What is total at the end?
total = 0 for n in range(1, 4): total = total + 10 total = total + 17.Follow this code by hand. What is the second number it prints?
total = 0 for n in range(2, 6): total = total + n print(total) print(total * 2)8.One of these four lines runs a different number of times from the other three. Which one?
for n in range(1, 4): print(n) print(n * 2) print(n * 3) print(0)- a) The line printing n times 2
- b) The line printing n
- c) The line printing n times 3
- d) The line printing 0
Blocks and indentation · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 11 of 13
Loops inside loops
Work out how many times the body of a loop inside another loop runs, and in what order the two counters change.
1.Follow this code by hand. What is total at the end?
total = 0 for a in range(1, 4): for b in range(1, 4): total = total + a * b2.Follow this code by hand. What is the second number it prints?
for a in range(1, 4): for b in range(1, 4): print(a * 10 + b)3.In this program, which line runs the greatest number of times?
for a in range(1, 6): print(a) for b in range(1, 4): print(b) print(0)- a) The line printing b
- b) The line printing a
- c) The line printing 0
- d) The heading of the inner loop
4.In each of these, one loop sits inside another with a single line at the deepest level. Match each pair of ranges to how many times that line runs.
- range(1, 3) outside, range(1, 6) inside
- range(1, 4) outside, range(1, 8) inside
- range(1, 5) outside, range(1, 3) inside
- range(2, 5) outside, range(1, 5) inside
- range(1, 10) outside, range(1, 3) inside
- 21
- 18
- 8
- 10
- 12
5.A loop sits inside another loop. The inner range is made one longer while the outer range is left exactly as it was. What happens to the number of times the deepest line runs?
- a) It stays exactly the same
- b) It goes up by one
- c) It doubles
- d) It goes up by the number of trips the outer loop makes
6.Follow this code by hand. How many times does the most deeply indented line run?
for a in range(1, 4): for b in range(1, 5): print(a * b)7.Follow this code by hand. What is count at the end? Notice that the inner range depends on the outer counter.
count = 0 for row in range(1, 5): for star in range(1, row + 1): count = count + 18.In each of these, one loop sits inside another with a single line at the deepest level. Sort each one by how many times that line runs.
Groups: Eight times · Fifteen times
- range(0, 5) outside, range(0, 3) inside
- range(1, 3) outside, range(1, 5) inside
- range(3, 8) outside, range(4, 7) inside
- range(2, 6) outside, range(3, 5) inside
- range(1, 6) outside, range(2, 5) inside
- range(4, 8) outside, range(1, 3) inside
Loops inside loops · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 12 of 13
Procedures, and calling them
Read a program that gives a block of lines a name, and say what runs, when, and how many times.
1.This program prints four numbers. Put them in the order they appear on the screen.
def middle(): print(9) print(5) print(7) middle() print(1)- 1
- 9
- 5
- 7
2.The named block has a loop inside it. How many numbers does it print?
def show(): for n in range(1, 4): print(n) show() show()3.A procedure whose body is a single printing line is used in five different programs. Match each way of using it to how many times its body runs.
- Defined but never called
- Called once at the end of the program
- Called inside a loop over range(1, 6)
- Called twice, and again inside a loop over range(1, 5)
- Called inside a loop over range(1, 3) that itself sits inside a loop over range(1, 5)
- 1
- 5
- 6
- 8
- 0
4.Follow this code by hand. How many times does the line printing 3 run?
def step(): print(3) for n in range(1, 5): step()5.Read this program from the top down. How many numbers does it print?
def show(): print(5)- a) 0
- b) It cannot be run at all
- c) 5
- d) 1
6.One named block calls another. How many numbers does it print?
def inner(): print(1) def outer(): inner() inner() outer()7.The named block below is called twice. How many numbers does it print?
def show(): print(1) print(2) show() show()8.A loop calls a block that calls another block. How many numbers does it print?
def inner(): print(1) def outer(): inner() inner() for n in range(1, 5): outer()
Procedures, and calling them · Class 8 Computer Science · www.arenapublications.com/learn
Class 8 Computer Science · 13 of 13
Procedures that take values and give one back
Read a procedure that is handed values to work on, and work out what a call to it gives.
1.Two calls happen one after the other here. What number does it print?
def treble(x): return x * 3 a = treble(3) b = treble(a) print(b)2.This procedure multiplies and then adds. What number does it print?
def cost(n): return n * 5 + 2 print(cost(6))3.A procedure named grow takes a number and gives back that number plus a tenth of it. Which of these calls gives 55?
- a) grow(50)
- b) grow(45)
- c) grow(60)
- d) grow(55)
4.One call sits inside another here. What number does it print?
def double(x): return x * 2 print(double(double(3)))5.Follow this code by hand. What is total at the end?
def add(a, b): return a + b total = 0 for n in range(1, 5): total = add(total, n)6.This procedure has a loop inside it. What number does it print?
def upto(n): total = 0 for k in range(1, n + 1): total = total + k return total print(upto(5))7.This procedure is handed two values rather than one. What number does it print?
def add(a, b): return a + b print(add(4, 9))8.This procedure takes something off what it is handed. What number does it print?
def less(x): return x - 5 print(less(30))
Procedures that take values and give one back · Class 8 Computer Science · www.arenapublications.com/learn
Answer keys — Class 8 Computer Science
In the same order as the worksheets.
Hexadecimal numbers
- 1. a) 255
- 2. 2D
- 3. 58
- 4. 1. 1F 2. 2A 3. 4D 4. B0 5. FF
- 5. 10100111
- 6. C8
- 7. 4 → 0100; 7 → 0111; 9 → 1001; D → 1101; E → 1110
- 8. D6
Text as numbers
- 1. 102
- 2. 32
- 3. H
- 4. 68
- 5. 1. the digit character 7 2. capital B 3. capital M 4. small d 5. small z
- 6. 70 → A capital letter; 99 → A small letter; 88 → A capital letter; 104 → A small letter; 78 → A capital letter; 115 → A small letter
- 7. YES → 3; HELLO → 5; OK NOW → 6; GOODBYE → 7; I AM HERE → 9
- 8. 8
The boxes that make a network work
- 1. a) No — both machines are on the same network, so the switch can deliver it by itself
- 2. 12
- 3. a) A router
- 4. 1
- 5. 8
- 6. d) Let a device with no cable of its own join the network
- 7. 7
- 8. a) Far fewer copies of each message are being put on the cables, so there is less traffic to get through
The shapes a network is built in
- 1. 3 computers → 3; 8 computers → 28; 9 computers → 36; 10 computers → 45; 12 computers → 66
- 2. 6
- 3. 6
- 4. c) The computer on the far end of that cable is cut off, and the rest carry on as before
- 5. 1. A bus joining four computers along one long cable 2. A star joining four computers to a switch 3. A mesh joining four computers 4. A mesh joining five computers
- 6. 10
- 7. a) The number of cables climbs far faster than the number of computers does
- 8.
- 0
- none
Addresses and names on a network
- 1. 71
- 2. d) Saying which number belongs to a given name
- 3.
- fourth
- the fourth
- last
- the last
- 4. 1. The browser is handed a name 2. The browser asks a name service which number goes with that name 3. The name service answers with the number 4. The browser sends its request to that number
- 5. b) Messages meant for one of them can arrive at the other, because the address no longer says which machine is which
- 6. 32
- 7. c) What the name service answers when it is asked about that name
- 8. d) 192.168.0.300
Spreadsheet functions
- 1. =MAX(M1:M4) → Shows 15; =SUM(M2:M4) → Shows something else; =MIN(M1:M4) → Shows something else; =M3 → Shows 15; =SUM(M1:M2)+2 → Shows 15; =COUNT(M1:M4) → Shows something else
- 2. Full marks
- 3. Pass
- 4. d) 9
- 5. 7.5
- 6. Not over
- 7. 1. =MIN(Q1:Q4) 2. =COUNT(Q1:Q4) 3. =AVERAGE(Q1:Q4) 4. =MAX(Q1:Q4) 5. =SUM(Q1:Q4)
- 8. 7
Copying formulas, and references that stay put
- 1. 1. L5 2. L4 3. L3 4. L2
- 2. C4
- 3. G4
- 4. M3
- 5. F1
- 6. N4
- 7. I1
- 8. a) =$A2*B$1
Charts from a spreadsheet
- 1. d) A slice shows a share of one whole, and four temperatures added together make no whole of anything
- 2. 2 — The second shop
- 3. d) A pie chart
- 4. c) Makes it look far bigger than it is
- 5. 8
- 6. 15
- 7. 10
- 8. 90
Loops that count
- 1. range(1, 6) → 5; range(4, 9) → 8; range(0, 3) → 2; range(7, 11) → 10; range(2, 15) → 14
- 2. 24
- 3. c) 0
- 4. 10
- 5. for n in range(1, 4): → Three times; for n in range(0, 4): → Four times; for n in range(5, 8): → Three times; for n in range(2, 6): → Four times; for n in range(7, 10): → Three times; for n in range(10, 14): → Four times
- 6. 10
- 7. 94
- 8. 10
Blocks and indentation
- 1. total = 0 → Runs once; total = total + n → Runs three times; print(n) → Runs three times; print(total) → Runs once; print(total * 2) → Runs once
- 2. 1. 5 2. 10 3. 15 4. 3
- 3. 202
- 4. a) The printing line is indented, so it sits inside the loop and runs every trip round
- 5. 6
- 6. 31
- 7. 28
- 8. d) The line printing 0
Loops inside loops
- 1. 36
- 2. 12
- 3. a) The line printing b
- 4. range(1, 3) outside, range(1, 6) inside → 10; range(1, 4) outside, range(1, 8) inside → 21; range(1, 5) outside, range(1, 3) inside → 8; range(2, 5) outside, range(1, 5) inside → 12; range(1, 10) outside, range(1, 3) inside → 18
- 5. d) It goes up by the number of trips the outer loop makes
- 6. 12
- 7. 10
- 8. range(2, 6) outside, range(3, 5) inside → Eight times; range(1, 6) outside, range(2, 5) inside → Fifteen times; range(1, 3) outside, range(1, 5) inside → Eight times; range(0, 5) outside, range(0, 3) inside → Fifteen times; range(4, 8) outside, range(1, 3) inside → Eight times; range(3, 8) outside, range(4, 7) inside → Fifteen times
Procedures, and calling them
- 1. 1. 7 2. 9 3. 5 4. 1
- 2. 6
- 3. Defined but never called → 0; Called once at the end of the program → 1; Called inside a loop over range(1, 6) → 5; Called twice, and again inside a loop over range(1, 5) → 6; Called inside a loop over range(1, 3) that itself sits inside a loop over range(1, 5) → 8
- 4. 4
- 5. a) 0
- 6. 2
- 7. 4
- 8. 8
Procedures that take values and give one back
- 1. 27
- 2. 32
- 3. a) grow(50)
- 4. 12
- 5. 10
- 6. 15
- 7. 13
- 8. 25
Class 8 Computer Science · www.arenapublications.com/learn