Term pack
Year 11 Computing
Name: ________________________
Skills in this pack
- Changing and growing a list
- Dictionaries and their keys
- Looping over a dictionary
- Writing and reading a file
- Going through a file line by line
- Counting and adding with a condition
- Looking a value up in a table
- Sorting and filtering a sheet
- What a page is made of
- Asking and answering over the web
- Tables, records and fields
- Asking a database a question
Free at www.arenapublications.com/learn — no account, no ads, ever.
Year 11 Computing · 1 of 12
Changing and growing a list
Work out what a list holds after values have been added on the end, written over, or joined on from another list.
1.A list called pins holds [8, 3]. Each of these lines is run on its own, starting from that list every time. Put them in order of how many values pins holds afterwards, fewest first.
- pins.append(9)
- pins[0] = 4
- pins = pins + [6, 7, 0]
- pins = pins + [1, 2]
2.Two values are added on the end, one after the other. What does this program print?
bag = [3] bag.append(7) bag.append(2) print(bag[1] + bag[2])
3.A value is written over, and then the list is measured. What does this program print?
sizes = [5, 2, 9] sizes[0] = 40 print(len(sizes))
4.Two lists are joined into a third one here. What does this program print?
first = [1, 2] second = [7, 8, 9] both = first + second print(len(both))
5.Something is added on the end and something else is written over. What does this program print?
row = [2, 4, 6] row.append(8) row[0] = 10 print(row[0] + row[3])
6.Something is added on the end, and then a position from before the change is asked for. What does the program print?
marks = [12, 7, 20] marks.append(5) print(marks[2])
7.Two lists are joined, and then a position is asked for out of the joined one. What does this program print?
a = [10, 20] b = [30, 40, 50] c = a + b print(c[3])
8.A list called box already holds four values. Sort each line by what it does to how long the list is.
Groups: Makes the list longer · Leaves the length alone
- box[0] = 7
- box.append(0)
- box.append(7)
- box.append(12)
- box[3] = 1
- box[2] = 9
Changing and growing a list · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 2 of 12
Dictionaries and their keys
Look a value up in a dictionary by its key, and work out what adding a key or writing over one leaves behind.
1.A key the dictionary did not have is written to here. What does this program print?
stock = {"pen": 12, "book": 5} stock["bag"] = 9 print(len(stock))2.A dictionary called scores holds {"red": 14, "blue": 6, "green": 22, "black": 9}. Put these lookups in order of the number each one gives, smallest first.
- scores["blue"]
- scores["red"]
- scores["green"]
- scores["black"]
3.This dictionary starts with nothing in it at all. What does this program print?
seen = {} seen["pen"] = 2 seen["bag"] = 5 print(len(seen))4.You want to find one particular thing that a program has stored. What is the difference between a list and a dictionary here?
- a) A dictionary is looked in by position as well, starting from 0 like a list does
- b) A list can hold only numbers, and a dictionary only writing
- c) A list is looked in by position, and a dictionary by a key that whoever wrote the program chose
- d) A dictionary numbers its keys as they go in, so its first key is key 0
5.This line looks just like the last one, but the key it writes to is not new. What does this program print?
counts = {"red": 3, "blue": 8} counts["red"] = 10 print(len(counts))6.Two values are looked up and added together. What does this program print?
weights = {"box": 25, "bag": 40, "cup": 5} print(weights["box"] + weights["cup"])7.A value is looked up by name rather than by position here. What does this program print?
prices = {"pen": 10, "book": 45, "bag": 90} print(prices["book"])8.One of these two lines adds a pair and the other one does not. What does this program print?
stock = {"pen": 6} stock["book"] = 3 stock["pen"] = 11 print(stock["pen"] + stock["book"])
Dictionaries and their keys · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 3 of 12
Looping over a dictionary
Follow a loop that visits every key in a dictionary, looks each value up, and leaves a total or a count behind.
1.A loop adds every value of a dictionary into a total that starts at 0. Sort each dictionary by the total that loop reaches.
Groups: The total comes to 10 · The total comes to 20
- {"pen": 3, "bag": 3, "cup": 4}
- {"pen": 15, "bag": 5}
- {"pen": 6, "bag": 6, "cup": 8}
- {"pen": 1, "bag": 9}
- {"pen": 8, "bag": 12}
- {"pen": 4, "bag": 6}
2.There is a decision inside this loop, so not every key adds to the counter. What does the program print?
sales = {"north": 12, "south": 30, "east": 5, "west": 22} busy = 0 for place in sales: if sales[place] > 20: busy = busy + 1 print(busy)3.A dictionary is built from scratch inside this loop, and one thing in the list turns up twice. What does the program print?
counts = {} for word in ["pen", "bag", "pen"]: counts[word] = 1 print(len(counts))4.Only the values that get past the comparison reach the total here. What does the program print?
hours = {"mon": 3, "tue": 8, "wed": 2, "thu": 9} long = 0 for day in hours: if hours[day] >= 8: long = long + hours[day] print(long)5.A program sets total to 0 and then runs "for k in prices:" over the dictionary {"pen": 5, "bag": 10, "cup": 15}, with one of these lines as the body. Match each body to what total holds at the end.
- total = total + prices[k]
- total = total + 1
- total = total + 2
- total = prices[k]
- total = total + (prices[k] * 2)
- 30
- 15
- 6
- 3
- 60
6.This loop prints as it goes, and a dictionary is walked in the order its pairs were written. What is the last number it prints?
sizes = {"small": 2, "large": 7} for name in sizes: print(sizes[name])7.Every value in this dictionary is added into a running total. What does the program print?
stock = {"pen": 4, "book": 9, "bag": 2} total = 0 for key in stock: total = total + stock[key] print(total)8.A loop counts how many of a dictionary's values are over 10. Put these dictionaries in order of that count, fewest first.
- {"pen": 15, "bag": 20, "cup": 30}
- {"pen": 12, "bag": 3}
- {"pen": 4, "bag": 2}
- {"pen": 11, "bag": 40, "cup": 2}
Looping over a dictionary · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 4 of 12
Writing and reading a file
Follow a program that saves writing into a file and reads it back, and work out what the file holds at each point.
1.The number saved here is read back and used in a sum. What does the program print?
f = open("count.txt", "w") f.write("7") f.close() f = open("count.txt", "r") n = int(f.read()) f.close() print(n * 3)2.The same file is opened for writing twice here, and each opening writes something different. How many lines does the file hold when this program has finished?
f = open("log.txt", "w") f.write("first\n") f.close() f = open("log.txt", "w") f.write("red\nblue\n") f.close()3.What comes back from readlines() is an ordinary list, so a position can be asked for out of it. Which word does this program print?
f = open("names.txt", "w") f.write("pen\nbag\ncup\n") f.close() f = open("names.txt", "r") lines = f.readlines() f.close() print(lines[1])4.What is read back out of this file is turned into a number before it is used. What does the program print?
f = open("score.txt", "w") f.write("40") f.close() f = open("score.txt", "r") text = f.read() f.close() print(int(text) + 2)5.This program saves three pieces of writing and then reads them back as a list. What does it print?
f = open("shades.txt", "w") f.write("red\ngreen\nblue\n") f.close() f = open("shades.txt", "r") lines = f.readlines() f.close() print(len(lines))6.A program saves some writing into a file and then reads it back. Put these five things in the order they have to happen.
- Read the lines back out
- Write the lines into it
- Open the same file again with "r"
- Close the file
- Open the file with "w"
7.A program writes one of these pieces of writing into a file and then reads it back with readlines(). Match each one to the number of lines that comes back.
- "red\n"
- "red\nblue\n"
- "red\nblue\ngreen\n"
- "red\nblue\ngreen\nblack\n"
- ""
- 1
- 3
- 0
- 4
- 2
8.Sort each of these by whether it changes what the file holds or only looks at what is there.
Groups: Changes what the file holds · Only looks at what is there
- f.write("red\n")
- f.write("9\n")
- f.readlines()
- open("notes.txt", "w")
- f.read()
- open("notes.txt", "r")
Writing and reading a file · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 5 of 12
Going through a file line by line
Follow a loop that visits every line of a file in turn, turns each line into a number where it needs to, and leaves a total or a count behind.
1.The numbers saved in this file are added up as the loop meets them. What does the program print?
f = open("marks.txt", "w") f.write("8\n3\n6\n") f.close() total = 0 f = open("marks.txt", "r") for line in f: total = total + int(line) f.close() print(total)2.The file this loop is given has nothing written in it at all. What does the program print?
f = open("empty.txt", "w") f.write("") f.close() total = 0 f = open("empty.txt", "r") for line in f: total = total + int(line) f.close() print(total)3.This loop prints as it goes rather than keeping anything back. What is the last number it prints?
f = open("steps.txt", "w") f.write("3\n5\n2\n") f.close() f = open("steps.txt", "r") for line in f: print(int(line) * 10) f.close()4.A loop over an open file is written as "for line in f:". What does line hold on each trip round?
- a) One character of the file
- b) One line of the file, as a piece of writing
- c) The number of the line, counting from 0
- d) The whole file, all at once
5.This loop keeps hold of the largest number it has seen so far. What does the program print?
f = open("temps.txt", "w") f.write("14\n39\n22\n") f.close() best = 0 f = open("temps.txt", "r") for line in f: if int(line) > best: best = int(line) f.close() print(best)6.A program adds up the numbers in a file, one line at a time. Someone then adds one more line to the file, holding 5, and the program is run again without being changed. What is different?
- a) The loop makes one more trip, and the total is 1 larger
- b) The total is 5 larger, but the loop makes the same number of trips as before
- c) The loop makes one more trip, and the total is 5 larger
- d) Nothing, because the program was not changed
7.A decision inside this loop lets only some of the lines reach the counter. What does the program print?
f = open("sales.txt", "w") f.write("12\n30\n5\n22\n") f.close() big = 0 f = open("sales.txt", "r") for line in f: if int(line) > 20: big = big + 1 f.close() print(big)8.Each of these files is read line by line and its numbers added into a total. Put the files in order of the total each one gives, smallest first.
- "1\n1\n1\n1\n"
- "2\n3\n"
- "6\n8\n"
- "9\n"
Going through a file line by line · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 6 of 12
Counting and adding with a condition
Work out what COUNTIF and SUMIF show for a sheet you are given, and read the test each of them is applying.
1.A sheet holds the words D1 = pen, D2 = bag, D3 = pen, D4 = cup and D5 = pen. What number does this formula show?
=COUNTIF(D1:D5, "pen")
2.A sheet holds J1 = 6, J2 = 18, J3 = 6, J4 = 25 and J5 = 11. Put these formulas in order of the number each one shows, smallest first.
- =COUNTIF(J1:J5, ">5")
- =COUNTIF(J1:J5, ">20")
- =COUNTIF(J1:J5, ">=11")
- =COUNTIF(J1:J5, "6")
3.A COUNTIF over the eight cells H1:H8, with the test ">50", shows 3. How many of those eight cells hold 50 or less?
4.A COUNTIF over a column of words is given the test "pen". Which cells does it count?
- a) Every cell that has anything at all written in it
- b) Every cell with the letters p, e and n somewhere in it
- c) The cells sitting in the same rows as the cells that say pen
- d) Only the cells that say pen and nothing else
5.A range holds the five values 5, 12, 20, 3 and 25. Sort each test by how many of those cells pass it.
Groups: Two cells pass · Three cells pass
- "<10"
- ">=20"
- ">=12"
- ">10"
- "<13"
- ">15"
6.A sheet holds F1 = 8, F2 = 14, F3 = 8 and F4 = 20. Match each formula to the number it shows.
- =COUNTIF(F1:F4, "8")
- =SUMIF(F1:F4, ">10")
- =COUNTIF(F1:F4, ">5")
- =SUMIF(F1:F4, "8")
- =COUNTIF(F1:F4, ">14")
- 16
- 1
- 4
- 34
- 2
7.A sheet holds C1 = 4, C2 = 15, C3 = 9 and C4 = 20. What number does this formula show?
=SUMIF(C1:C4, ">=10")
8.A sheet holds B1 = 12, B2 = 30, B3 = 5, B4 = 22 and B5 = 30. What number does this formula show?
=COUNTIF(B1:B5, ">20")
Counting and adding with a condition · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 7 of 12
Looking a value up in a table
Read a VLOOKUP: find the row its search value matches, and take the answer from the column its number names.
1.A sheet holds a table in A1:C4. Column A holds pen, bag, cup and map; column B holds 10, 40, 25 and 60; column C holds 5, 2, 9 and 4. What number does this formula show?
=VLOOKUP("bag", A1:C4, 3, FALSE)2.A table of names and prices fills A1:B5, and pen is the name in A1. Someone writes a lookup for pen but gives its range as A2:B5 by mistake. What happens?
- a) It works, because a lookup searches the whole sheet anyway
- b) It shows the price in B2, since that is the first row of the range
- c) Nothing is found, because the row holding pen is not inside the range the formula was given
- d) It shows an answer one row further down than it should
3.A sheet holds a table in A1:B4. Column A holds the names pen, bag, cup and map, and column B holds 10, 40, 25 and 60 beside them. What number does this formula show?
=VLOOKUP("cup", A1:B4, 2, FALSE)4.The first column of this table holds numbers rather than words: A1:A3 hold 101, 102 and 103, and B1:B3 hold 40, 55 and 70. What number does this formula show?
=VLOOKUP(102, A1:B3, 2, FALSE)
5.A table sits in C1:E4, away from the left edge of the sheet. Column C holds pen, bag, cup and map; column D holds 12, 30, 8 and 45; column E holds 7, 1, 6 and 3. What number does this formula show?
=VLOOKUP("pen", C1:E4, 3, FALSE)6.Two lookups into the same table are multiplied together here. Column A holds pen, bag, cup and map; column B holds 10, 40, 25 and 60; column C holds 5, 2, 9 and 4. What number does this formula show?
=VLOOKUP("cup", A1:C4, 2, FALSE) * VLOOKUP("cup", A1:C4, 3, FALSE)7.In the formula =VLOOKUP("cup", A1:C4, 2, FALSE), what does the 2 mean?
- a) Which row of the table to look in
- b) That the answer it shows has to be more than 2
- c) Which column of the table the answer is taken from, counting the table's own first column as 1
- d) How many matching rows the formula should expect to find
8.A table's first column holds pen, bag, cup and map, and the lookups below all use FALSE, which asks for an exact match. Sort each value being looked for by what the lookup does with it.
Groups: Finds a row · Finds nothing, and the formula shows an error
- "pen"
- "map"
- "bag"
- "hat"
- "jug"
- "tin"
Looking a value up in a table · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 8 of 12
Sorting and filtering a sheet
Work out what a sheet looks like after its rows have been put in order by a column, or narrowed to the rows that pass a test.
1.Sort each of these by whether it moves the sheet's rows about or only changes which of them you can see.
Groups: The rows change places · The rows stay where they are
- Switching a filter off again
- Sorting by a column, largest first
- Sorting by a column, smallest first
- Narrowing a filter so that fewer rows show
- Filtering to show only some of the rows
- Sorting by a second column where the first one ties
2.A filter is switched on so that only some rows show, and is then switched off again. What has happened to the rows that were hidden while it was on?
- a) They are back, but underneath the rows that were showing
- b) They are back, but the amounts in them have been emptied
- c) They have been deleted, and would have to be typed in again
- d) They are all back, exactly where they were — filtering never removed them from the sheet
3.These rows are sorted by column B, largest first. Which name ends up in the second row from the top?
A B 1 jar 18 2 tin 64 3 box 41 4 lid 6
4.This sheet is sorted by column B, largest first. Put the names in the order their rows end up in.
A B 1 pen 14 2 bag 3 3 cup 22 4 map 9
- cup
- pen
- map
- bag
5.A sheet's very first row holds the column headings rather than data. What has to be true for those headings to stay at the top when the sheet is sorted?
- a) Nothing — a heading row always stays at the top by itself
- b) The sort has to be told that the first row is headings and not one of the rows to be sorted
- c) The headings have to be in alphabetical order themselves
- d) The headings have to be deleted before sorting and typed in again afterwards
6.The rows of this sheet are sorted by column B, smallest first. Which name is in the top row afterwards?
A B 1 pen 30 2 bag 12 3 cup 45 4 map 7
7.A sheet of thirty rows is filtered so that twelve rows show. The filter is then switched off and the sheet is sorted by one of its columns. How many rows are showing now?
8.This sheet is sorted by column B, smallest first — and where two rows hold the same amount, by column A in alphabetical order. Which name is in the top row?
A B 1 pen 3 2 bag 5 3 cup 3 4 map 5
Sorting and filtering a sheet · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 9 of 12
What a page is made of
Work out how many separate files a browser has to fetch to show a page, and what changes when some of them are already stored.
1.Sort each of these by whether it arrives inside the HTML file itself or is a separate file the browser has to ask for.
Groups: Comes inside the HTML file · Is a separate file, asked for on its own
- A photograph on the page
- The stylesheet
- The picture that name refers to
- The name of a picture
- The words of a paragraph
- A heading
2.A page needs its HTML and four other files. The reader opens it again a moment later, and the browser has all four of the other files stored from the first visit but fetches the HTML afresh. How many files does it fetch this time?
3.A page's HTML is 6 KB and its stylesheet is 4 KB, and it names two pictures of 30 KB each. How many KB does the browser fetch altogether to show the page?
4.A page's files come to 90 KB altogether, of which the HTML is 5 KB. On a second visit everything except the HTML is already stored, and the HTML is fetched again. How many KB does the browser fetch this time?
5.A page's HTML names three pictures and one stylesheet, and needs nothing else. Counting the HTML itself, how many separate files must the browser fetch to show the page completely?
6.Put these pages in order of how many files a browser must fetch to show each one, fewest first.
- A page with one stylesheet and one picture
- A page with one stylesheet and three pictures
- A page with two stylesheets and five pictures
- A page of writing with no pictures and no stylesheet
7.A page's HTML names five pictures. One of the five has been deleted from the machine holding the page, and the other four are there. How many of the pictures appear on the screen?
8.A page needs eight files altogether. On a second visit the browser already has six of them stored, but the HTML has been changed since and must be fetched again, and there is one picture the browser has never seen. How many files does it fetch?
What a page is made of · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 10 of 12
Asking and answering over the web
Say what travels out in a request and what comes back in the answer, read the data an address carries, and follow what a browser does with the number it is answered with.
1.Put these addresses in order of how many name-and-value pairs each one carries, fewest first.
- /search?item=pen&size=large&count=4&page=2
- /s?a=1&b=2&c=3
- /find?q=pen
- /notices/exam/timetable?term=summer&stream=science
2.A form has four boxes. All four are filled in and sent as part of the address, on a path of /search. How many question marks does the address that goes out have in it?
3.Every answer that comes back over the web starts with a number. What is that number for?
- a) It says how the request went — whether it worked, and if not, what sort of thing went wrong
- b) It says how many files were sent back
- c) It is the position of the page on the machine holding it
- d) It is the size of what came back
4.Sort each of these by whether it travels out in the request or comes back in the answer.
Groups: Goes out in the request · Comes back in the answer
- The status number
- The new address a moved page has gone to
- The path of the page being asked for
- The HTML of the page
- The word GET or POST
- The name-and-value pairs after the question mark
5.A form's answers are sent as part of the address, so that they are still visible in the address bar once the page has loaded. Which of these is true of sending them that way?
- a) Only numbers can be sent that way, and words have to be sent another way
- b) The address bar is emptied as soon as the answers arrive
- c) The answers are hidden, because an address is not stored anywhere
- d) Anybody who can see the address can read the answers, and the address can be saved or passed on exactly as it is
6.A browser asks for a page and the answer that comes back is 500. Whose end has the problem?
- a) The machine holding the page
- b) The browser that asked
- c) The reader's own connection
- d) Nobody's — 500 means the page is there but empty
7.A browser sent ten requests for one page. Eight were answered 200, one was answered 301 and one was answered 404. The browser then follows the 301 and is answered 200. How many requests has it sent altogether by that point?
8.A browser asks for one HTML file and six pictures. Five of the seven answers come back 200, and the other two come back 404. How many pieces of the page are missing?
Asking and answering over the web · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 11 of 12
Tables, records and fields
Read a database table as records and fields, count what it holds, and say what a primary key is doing in it.
1.Put these tables in order of how many single pieces of information each one holds, fewest first.
- 5 records of 4 fields
- 4 records of 3 fields
- 10 records of 3 fields
- 2 records of 12 fields
2.A table has five fields and a hundred and twenty records. How many single pieces of information does it hold altogether?
3.A table holds one row for each of forty pupils, and every row has six columns. How many records does the table hold?
4.A table of two hundred pupils has a field holding the name of each pupil's form teacher, and the school has twenty form teachers. What is actually stored in that field?
- a) A number saying which teacher, with the names kept nowhere
- b) One teacher's name in every pupil's record, so most of the names are stored many times over
- c) Nothing, because a field cannot hold the same value twice
- d) Each teacher's name once, in the first record that needs it
5.Match each word to what it names in a database table.
- Record
- Field
- Primary key
- Table
- Value
- One column: one particular piece of information, asked of every row
- The field whose value is never repeated in two records
- All the records of one kind, kept together
- What one field holds in one record
- One row: everything the table holds about one thing
6.Two tables have exactly the same five fields as each other. One holds thirty records and the other forty-five. They are joined into a single table holding all of both. How many records does that table have?
7.What is a primary key for?
- a) It is the password that has to be given before the table will open
- b) It is whichever field happens to be the first column of the table
- c) It is the field whose value is different in every record, so that any one record can always be picked out
- d) It is the field the table is kept sorted by
8.A roll number that is meant to be a table's primary key is typed in twice by mistake, so two different records now hold 41. What can no longer be done?
- a) The other records lose their roll numbers
- b) No further records can be added to the table
- c) One record can no longer be picked out by giving its roll number alone
- d) The table can no longer be sorted by any of its fields
Tables, records and fields · Year 11 Computing · www.arenapublications.com/learn
Year 11 Computing · 12 of 12
Asking a database a question
Read a query as three separate decisions — which fields, which records, in what order — and work out how much comes back.
1.A query gives back six records and orders them by mark, largest first. The six marks are 44, 91, 67, 91, 30 and 55. What is the mark in the third row of the answer?
2.The answer to a query comes back as twelve rows of four columns. How many single values are in that answer?
3.A table holds five records whose marks are 40, 75, 62, 88 and 51. Match each condition to how many rows a query using it gives back.
- WHERE marks > 60
- WHERE marks > 80
- WHERE marks < 55
- WHERE marks > 30
- WHERE marks >= 51
- 3
- 4
- 1
- 5
- 2
4.A table holds fifty records. A query asks for the records where the mark is more than 60, and eighteen of the records have a mark like that. How many rows does the query give back?
5.A query asks for the records with a mark of more than 100, over a table whose largest mark is 98. How many rows does it give back?
6.A table holds forty records. Twenty-five have a mark over 60, thirty are in the swimming team, and twenty are both. How many records satisfy "mark over 60 OR in the swimming team"?
7.What does the WHERE part of a query decide?
- a) Which records come back
- b) The order the records come back in
- c) Which fields come back
- d) Which table is looked in
8.A table holds seven records whose marks are 12, 48, 65, 90, 33, 71 and 55. Put these conditions in order of how many rows a query using each one gives back, fewest first.
- WHERE marks > 70
- WHERE marks > 85
- WHERE marks > 60
- WHERE marks > 40
Asking a database a question · Year 11 Computing · www.arenapublications.com/learn
Answer keys — Year 11 Computing
In the same order as the worksheets.
Changing and growing a list
- 1. 1. pins[0] = 4 2. pins.append(9) 3. pins = pins + [1, 2] 4. pins = pins + [6, 7, 0]
- 2. 9
- 3. 3
- 4. 5
- 5. 18
- 6. 20
- 7. 40
- 8. box.append(7) → Makes the list longer; box[0] = 7 → Leaves the length alone; box.append(0) → Makes the list longer; box[3] = 1 → Leaves the length alone; box.append(12) → Makes the list longer; box[2] = 9 → Leaves the length alone
Dictionaries and their keys
- 1. 3
- 2. 1. scores["blue"] 2. scores["black"] 3. scores["red"] 4. scores["green"]
- 3. 2
- 4. c) A list is looked in by position, and a dictionary by a key that whoever wrote the program chose
- 5. 2
- 6. 30
- 7. 45
- 8. 14
Looping over a dictionary
- 1. {"pen": 4, "bag": 6} → The total comes to 10; {"pen": 15, "bag": 5} → The total comes to 20; {"pen": 3, "bag": 3, "cup": 4} → The total comes to 10; {"pen": 8, "bag": 12} → The total comes to 20; {"pen": 1, "bag": 9} → The total comes to 10; {"pen": 6, "bag": 6, "cup": 8} → The total comes to 20
- 2. 2
- 3. 2
- 4. 17
- 5. total = total + prices[k] → 30; total = total + 1 → 3; total = total + 2 → 6; total = prices[k] → 15; total = total + (prices[k] * 2) → 60
- 6. 7
- 7. 15
- 8. 1. {"pen": 4, "bag": 2} 2. {"pen": 12, "bag": 3} 3. {"pen": 11, "bag": 40, "cup": 2} 4. {"pen": 15, "bag": 20, "cup": 30}
Writing and reading a file
- 1. 21
- 2. 2
- 3. bag
- 4. 42
- 5. 3
- 6. 1. Open the file with "w" 2. Write the lines into it 3. Close the file 4. Open the same file again with "r" 5. Read the lines back out
- 7. "red\n" → 1; "red\nblue\n" → 2; "red\nblue\ngreen\n" → 3; "red\nblue\ngreen\nblack\n" → 4; "" → 0
- 8. f.write("red\n") → Changes what the file holds; f.read() → Only looks at what is there; open("notes.txt", "w") → Changes what the file holds; f.readlines() → Only looks at what is there; open("notes.txt", "r") → Only looks at what is there; f.write("9\n") → Changes what the file holds
Going through a file line by line
- 1. 17
- 2. 0
- 3. 20
- 4. b) One line of the file, as a piece of writing
- 5. 39
- 6. c) The loop makes one more trip, and the total is 5 larger
- 7. 2
- 8. 1. "1\n1\n1\n1\n" 2. "2\n3\n" 3. "9\n" 4. "6\n8\n"
Counting and adding with a condition
- 1. 3
- 2. 1. =COUNTIF(J1:J5, ">20") 2. =COUNTIF(J1:J5, "6") 3. =COUNTIF(J1:J5, ">=11") 4. =COUNTIF(J1:J5, ">5")
- 3. 5
- 4. d) Only the cells that say pen and nothing else
- 5. ">10" → Three cells pass; ">15" → Two cells pass; ">=20" → Two cells pass; ">=12" → Three cells pass; "<10" → Two cells pass; "<13" → Three cells pass
- 6. =COUNTIF(F1:F4, "8") → 2; =SUMIF(F1:F4, ">10") → 34; =COUNTIF(F1:F4, ">5") → 4; =SUMIF(F1:F4, "8") → 16; =COUNTIF(F1:F4, ">14") → 1
- 7. 35
- 8. 3
Looking a value up in a table
- 1. 2
- 2. c) Nothing is found, because the row holding pen is not inside the range the formula was given
- 3. 25
- 4. 55
- 5. 7
- 6. 225
- 7. c) Which column of the table the answer is taken from, counting the table's own first column as 1
- 8. "bag" → Finds a row; "hat" → Finds nothing, and the formula shows an error; "map" → Finds a row; "tin" → Finds nothing, and the formula shows an error; "pen" → Finds a row; "jug" → Finds nothing, and the formula shows an error
Sorting and filtering a sheet
- 1. Sorting by a column, smallest first → The rows change places; Filtering to show only some of the rows → The rows stay where they are; Sorting by a column, largest first → The rows change places; Switching a filter off again → The rows stay where they are; Sorting by a second column where the first one ties → The rows change places; Narrowing a filter so that fewer rows show → The rows stay where they are
- 2. d) They are all back, exactly where they were — filtering never removed them from the sheet
- 3. box
- 4. 1. cup 2. pen 3. map 4. bag
- 5. b) The sort has to be told that the first row is headings and not one of the rows to be sorted
- 6. map
- 7. 30
- 8. cup
What a page is made of
- 1. The words of a paragraph → Comes inside the HTML file; A photograph on the page → Is a separate file, asked for on its own; A heading → Comes inside the HTML file; The stylesheet → Is a separate file, asked for on its own; The name of a picture → Comes inside the HTML file; The picture that name refers to → Is a separate file, asked for on its own
- 2. 1
- 3. 70
- 4. 5
- 5. 5
- 6. 1. A page of writing with no pictures and no stylesheet 2. A page with one stylesheet and one picture 3. A page with one stylesheet and three pictures 4. A page with two stylesheets and five pictures
- 7. 4
- 8. 2
Asking and answering over the web
- 1. 1. /find?q=pen 2. /notices/exam/timetable?term=summer&stream=science 3. /s?a=1&b=2&c=3 4. /search?item=pen&size=large&count=4&page=2
- 2. 1
- 3. a) It says how the request went — whether it worked, and if not, what sort of thing went wrong
- 4. The path of the page being asked for → Goes out in the request; The status number → Comes back in the answer; The name-and-value pairs after the question mark → Goes out in the request; The HTML of the page → Comes back in the answer; The word GET or POST → Goes out in the request; The new address a moved page has gone to → Comes back in the answer
- 5. d) Anybody who can see the address can read the answers, and the address can be saved or passed on exactly as it is
- 6. a) The machine holding the page
- 7. 11
- 8. 2
Tables, records and fields
- 1. 1. 4 records of 3 fields 2. 5 records of 4 fields 3. 2 records of 12 fields 4. 10 records of 3 fields
- 2.
- 600
- six hundred
- 3. 40
- 4. b) One teacher's name in every pupil's record, so most of the names are stored many times over
- 5. Record → One row: everything the table holds about one thing; Field → One column: one particular piece of information, asked of every row; Primary key → The field whose value is never repeated in two records; Table → All the records of one kind, kept together; Value → What one field holds in one record
- 6. 75
- 7. c) It is the field whose value is different in every record, so that any one record can always be picked out
- 8. c) One record can no longer be picked out by giving its roll number alone
Asking a database a question
- 1. 67
- 2. 48
- 3. WHERE marks > 60 → 3; WHERE marks > 80 → 1; WHERE marks < 55 → 2; WHERE marks > 30 → 5; WHERE marks >= 51 → 4
- 4. 18
- 5. 0
- 6. 35
- 7. a) Which records come back
- 8. 1. WHERE marks > 85 2. WHERE marks > 70 3. WHERE marks > 60 4. WHERE marks > 40
Year 11 Computing · www.arenapublications.com/learn