← Back to Grade 10 Computer Science

Term pack

Grade 10 Computer Science

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.

Grade 10 Computer Science · 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. 1.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))
  2. 2.A list called nums holds [2, 4, 6]. Each of these lines is run on its own, starting from that same list every time. Match each line to what nums holds afterwards.

    • nums.append(8)
    • nums[0] = 8
    • nums[2] = 0
    • nums = nums + [1, 3]
    • nums[1] = 5
    • [2, 4, 0]
    • [2, 4, 6, 8]
    • [8, 4, 6]
    • [2, 5, 6]
    • [2, 4, 6, 1, 3]
  3. 3.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])
  4. 4.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 = pins + [1, 2]
    • pins[0] = 4
    • pins = pins + [6, 7, 0]
    • pins.append(9)
  5. 5.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))
  6. 6.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])
  7. 7.A value is written over here rather than added on. What does this program print?

    scores = [3, 8, 1, 6]
    scores[1] = 10
    print(scores[1] + scores[3])
  8. 8.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])

Changing and growing a list · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.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"])
  2. 2.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 dictionary numbers its keys as they go in, so its first key is key 0
    • d) A list is looked in by position, and a dictionary by a key that whoever wrote the program chose
  3. 3.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["black"]
    • scores["red"]
    • scores["green"]
  4. 4.A dictionary called sizes already holds the keys small, medium and large. Sort each line by what it does to the dictionary.

    Groups: Adds a new pair · Changes a pair already there

    • sizes["large"] = 1
    • sizes["small"] = 4
    • sizes["giant"] = 6
    • sizes["tiny"] = 2
    • sizes["medium"] = 7
    • sizes["huge"] = 9
  5. 5.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"])
  6. 6.This dictionary starts with nothing in it at all. What does this program print?

    seen = {}
    seen["pen"] = 2
    seen["bag"] = 5
    print(len(seen))
  7. 7.A dictionary holds the keys pen, book and bag. A program then asks it for the value under the key cup. Why is that a mistake?

    • a) The key cup would have to be a number rather than a word
    • b) There is no such key, so there is no value for the dictionary to give back
    • c) Keys have to be looked up in the order they were put in
    • d) A dictionary can only be asked for one of its keys once
  8. 8.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))

Dictionaries and their keys · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.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
    • 3
    • 60
    • 6
  2. 2.Two separate loops here feed the same total, one after the other. What does the program print?

    left = {"pen": 3, "bag": 4}
    right = {"cup": 5}
    total = 0
    for k in left:
        total = total + left[k]
    for k in right:
        total = total + right[k]
    print(total)
  3. 3.This loop keeps hold of two things at once: the best value it has seen, and the key that value came from. Which word does the program print?

    votes = {"red": 12, "blue": 30, "green": 21}
    best = ""
    top = 0
    for name in votes:
        if votes[name] > top:
            top = votes[name]
            best = name
    print(best)
  4. 4.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])
  5. 5.A loop counts how many of a dictionary's values are over 10. Put these dictionaries in order of that count, fewest first.

    • {"pen": 12, "bag": 3}
    • {"pen": 4, "bag": 2}
    • {"pen": 15, "bag": 20, "cup": 30}
    • {"pen": 11, "bag": 40, "cup": 2}
  6. 6.A loop over a dictionary is written as "for name in sizes:". What does name hold each time round?

    • a) A position, counting from 0
    • b) A whole pair, key and value together
    • c) One of the keys
    • d) One of the values
  7. 7.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)
  8. 8.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))

Looping over a dictionary · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.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)
  2. 2.A program reads a file of several lines using readlines(). What does readlines() hand back?

    • a) A list, with one piece of writing in it for each line of the file
    • b) A dictionary, with the line numbers as its keys
    • c) A number saying how many lines the file holds
    • d) One long piece of writing with the whole file in it
  3. 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. 4.A file holds the single line 12. A program opens it, reads that line and holds on to it. What sort of thing is the program holding?

    • a) A number, ready to be added to something straight away
    • b) Nothing at all until the file has been closed again
    • c) A piece of writing, which has to be turned into a number before it can be added to anything
    • d) A list holding the digit 1 and the digit 2
  5. 5.Two separate writes go into one opening of the file here. What does the program print?

    f = open("list.txt", "w")
    f.write("red\n")
    f.write("blue\n")
    f.close()
    f = open("list.txt", "r")
    lines = f.readlines()
    f.close()
    print(len(lines))
  6. 6.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()
  7. 7.A program saves some writing into a file and then reads it back. Put these five things in the order they have to happen.

    • Write the lines into it
    • Open the same file again with "r"
    • Open the file with "w"
    • Read the lines back out
    • Close the file
  8. 8.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))

Writing and reading a file · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.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)
  2. 2.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 5 larger
    • b) The total is 5 larger, but the loop makes the same number of trips as before
    • c) Nothing, because the program was not changed
    • d) The loop makes one more trip, and the total is 1 larger
  3. 3.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)
  4. 4.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)
  5. 5.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()
  6. 6.A program opens a file, goes through it with a line loop, and closes it again. Sort each of these lines of code by how often it runs.

    Groups: Runs once, outside the loop · Runs once for every line in the file

    • print(total)
    • print(int(line) * 2)
    • f.close()
    • f = open("data.txt", "r")
    • total = 0
    • total = total + int(line)
  7. 7.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)
  8. 8.Nothing in these lines is a number, and the loop does not try to make one. What does the program print?

    f = open("shades.txt", "w")
    f.write("red\ngreen\nblue\nblack\n")
    f.close()
    count = 0
    f = open("shades.txt", "r")
    for line in f:
        count = count + 1
    f.close()
    print(count)

Going through a file line by line · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.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
    • 4
    • 1
    • 34
    • 2
  2. 2.A COUNTIF over a column of words is given the test "pen". Which cells does it count?

    • a) Every cell with the letters p, e and n somewhere in it
    • b) Only the cells that say pen and nothing else
    • c) Every cell that has anything at all written in it
    • d) The cells sitting in the same rows as the cells that say pen
  3. 3.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

    • "<13"
    • ">15"
    • ">10"
    • ">=12"
    • ">=20"
    • "<10"
  4. 4.A sheet holds marks in K1:K4 — 45, 80, 62 and 90 — and the prizes those pupils won in L1:L4 — 1, 5, 2 and 8. What number does this formula show?

    =SUMIF(K1:K4, ">60", L1:L4)
  5. 5.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, ">=11")
    • =COUNTIF(J1:J5, ">5")
    • =COUNTIF(J1:J5, "6")
    • =COUNTIF(J1:J5, ">20")
  6. 6.A COUNTIF over the eight cells H1:H8, with the test ">50", shows 3. How many of those eight cells hold 50 or less?

  7. 7.What are the two things a COUNTIF is given?

    • a) A range of cells, and the number that the cells in it are expected to add up to
    • b) A range of cells to look at, and a test that each of those cells either passes or fails
    • c) Two ranges of cells, the second saying which of the first to count
    • d) A test, and the number of cells that ought to pass it
  8. 8.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")

Counting and adding with a condition · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.A lookup for map over a four-row table shows 60. The rows of the table are then shuffled so that the map row is the first one, and the same formula is run again over the same range. What number does it show now?

  2. 2.A table sits in A1:B4, with pen, bag, cup and map down column A. A lookup for cup shows 25. Which cell of the sheet is that 25 actually sitting in?

  3. 3.A table sits in A1:B5. Column A holds pen, bag, cup, map and tin; column B holds 14, 9, 31, 6 and 22. Match each value being looked for to the number a lookup of column 2 shows for it.

    • "pen"
    • "cup"
    • "tin"
    • "bag"
    • "map"
    • 31
    • 22
    • 14
    • 9
    • 6
  4. 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. 5.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)
  6. 6.This table has the same name in it twice by mistake. Column A holds pen, bag, pen and cup, and column B holds 10, 40, 25 and 60. A lookup goes down the first column and stops at the first row that matches. What number does this formula show?

    =VLOOKUP("pen", A1:B4, 2, FALSE)
  7. 7.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)
  8. 8.A table sits in A1:B4, with pen, bag, cup and map down column A and 30, 12, 45 and 7 beside them in column B. Put these lookups in order of the number each one shows, smallest first.

    • =VLOOKUP("pen", A1:B4, 2, FALSE)
    • =VLOOKUP("bag", A1:B4, 2, FALSE)
    • =VLOOKUP("cup", A1:B4, 2, FALSE)
    • =VLOOKUP("map", A1:B4, 2, FALSE)

Looking a value up in a table · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.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
    • map
    • bag
    • pen
    • cup
  2. 2.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
  3. 3.A sheet holds ten rows. A filter is switched on to show only the rows whose amount is more than 20, and six rows meet that test. How many rows are hidden?

  4. 4.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 have been deleted, and would have to be typed in again
    • c) They are back, but the amounts in them have been emptied
    • d) They are all back, exactly where they were — filtering never removed them from the sheet
  5. 5.A sheet of twelve rows is filtered to show only amounts of more than 20, and five rows show. The test is then changed to more than 10, and nine rows show. How many rows hold an amount that is more than 10 but not more than 20?

  6. 6.Someone selects only column B of a sheet, leaving the names in column A unselected, and sorts it. What has happened to the sheet?

    • a) The names in column A have been put in order as well
    • b) The amounts are in order, but each one now sits beside a name it never belonged to
    • c) The sheet refuses to sort until the whole of it is selected
    • d) Nothing has gone wrong — the rest of each row is carried along automatically
  7. 7.A sheet holds six rows whose amounts are 5, 22, 30, 14, 8 and 30. Match each filter test to how many rows are left showing.

    • More than 4
    • More than 25
    • More than 13
    • Less than 6
    • More than 20
    • 3
    • 6
    • 1
    • 4
    • 2
  8. 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 · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.A browser fetched nine files to show one page. One of the nine was the HTML and two were stylesheets, and every other one was a picture. How many pictures does the page have?

  2. 2.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?

  3. 3.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?

  4. 4.Two pages hold the same amount altogether: one is a single large picture, and the other is twenty small ones. The twenty usually take longer to appear. Why?

    • a) Small pictures are stored in a slower way than large ones
    • b) A browser can only draw one small picture at a time
    • c) Twenty small pictures always come to more than one large one
    • d) Each file has to be asked for separately, and every one of those asks takes its own time
  5. 5.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?

  6. 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 of writing with no pictures and no stylesheet
    • A page with two stylesheets and five pictures
    • A page with one stylesheet and three pictures
  7. 7.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

    • The stylesheet
    • A heading
    • The name of a picture
    • The words of a paragraph
    • The picture that name refers to
    • A photograph on the page
  8. 8.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?

What a page is made of · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.Match each status number to what the answer carrying it is saying.

    • 200
    • 404
    • 301
    • 500
    • 403
    • Something went wrong at this end while I was answering
    • Here is what you asked for
    • There is nothing here by that name
    • It has moved — ask again at this other address
    • It is here, but you are not allowed to see it
  2. 2.A browser asks for a page and the answer that comes back is 500. Whose end has the problem?

    • a) The reader's own connection
    • b) The browser that asked
    • c) The machine holding the page
    • d) Nobody's — 500 means the page is there but empty
  3. 3.A form sends three answers as part of the address. One more box is then added to the form and filled in as well. How many ampersands does the address carry now?

  4. 4.An address ends with the piece shown below. How many name-and-value pairs is it carrying?

    ?topic=lists&sort=new&page=3
  5. 5.Every answer that comes back over the web starts with a number. What is that number for?

    • a) It is the position of the page on the machine holding it
    • b) It says how many files were sent back
    • c) It says how the request went — whether it worked, and if not, what sort of thing went wrong
    • d) It is the size of what came back
  6. 6.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) The address bar is emptied as soon as the answers arrive
    • b) Anybody who can see the address can read the answers, and the address can be saved or passed on exactly as it is
    • c) The answers are hidden, because an address is not stored anywhere
    • d) Only numbers can be sent that way, and words have to be sent another way
  7. 7.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 path of the page being asked for
    • The name-and-value pairs after the question mark
    • The HTML of the page
    • The word GET or POST
    • The new address a moved page has gone to
    • The status number
  8. 8.A browser asks for an address and is answered 301. It asks again at the address it was pointed to, and is answered 200. How many requests did the browser send altogether?

Asking and answering over the web · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.A table holds one row for each of forty pupils, and every row has six columns. How many records does the table hold?

  2. 2.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) No further records can be added to the table
    • b) One record can no longer be picked out by giving its roll number alone
    • c) The table can no longer be sorted by any of its fields
    • d) The other records lose their roll numbers
  3. 3.A table has eight fields and fifty records. A ninth field is then added, and three records are deleted. How many records does the table hold now?

  4. 4.A table holds ninety-six single pieces of information altogether, and it has eight fields. How many records does it have?

  5. 5.A table has five fields and a hundred and twenty records. How many single pieces of information does it hold altogether?

  6. 6.Put these tables in order of how many single pieces of information each one holds, fewest first.

    • 4 records of 3 fields
    • 10 records of 3 fields
    • 2 records of 12 fields
    • 5 records of 4 fields
  7. 7.A table of six fields and thirty records is shown on screen with a heading row above it naming the fields. How many rows are on the screen altogether?

  8. 8.A table of two hundred records has a field called roll number, and that field is the table's primary key. At most how many records can hold the roll number 57?

Tables, records and fields · Grade 10 Computer Science · www.arenapublications.com/learn

Grade 10 Computer Science · 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. 1.A table of pupils has six fields. How many columns does the answer to this query have?

    SELECT name, marks FROM pupils WHERE marks > 60
  2. 2.A query orders its answer by mark, largest first, and where two records hold the same mark, by roll number, smallest first. Three records come back: roll 7 with mark 91, roll 3 with mark 91, and roll 9 with mark 60. Which roll number is in the top row?

  3. 3.A query says SELECT * rather than naming any fields. What comes back?

    • a) Nothing, until the fields wanted are named
    • b) Every field, for every record that passed the condition
    • c) Every record, but only the first field of each
    • d) Every field, but only for the first record
  4. 4.The answer to a query comes back as twelve rows of four columns. How many single values are in that answer?

  5. 5.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?

  6. 6.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
    • 1
    • 5
    • 4
    • 2
    • 3
  7. 7.Sort each piece of a query by what it decides about the answer.

    Groups: Decides which records come back · Decides which fields come back

    • WHERE marks > 60
    • WHERE house = 'red'
    • SELECT name, house, marks
    • WHERE marks < 40
    • SELECT name, marks
    • SELECT roll
  8. 8.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"?

Asking a database a question · Grade 10 Computer Science · www.arenapublications.com/learn

Answer keys — Grade 10 Computer Science

In the same order as the worksheets.

Changing and growing a list

  1. 1. 5
  2. 2. nums.append(8) → [2, 4, 6, 8]; nums[0] = 8 → [8, 4, 6]; nums[2] = 0 → [2, 4, 0]; nums = nums + [1, 3] → [2, 4, 6, 1, 3]; nums[1] = 5 → [2, 5, 6]
  3. 3. 9
  4. 4. 1. pins[0] = 4 2. pins.append(9) 3. pins = pins + [1, 2] 4. pins = pins + [6, 7, 0]
  5. 5. 3
  6. 6. 18
  7. 7. 16
  8. 8. 40

Dictionaries and their keys

  1. 1. 14
  2. 2. d) A list is looked in by position, and a dictionary by a key that whoever wrote the program chose
  3. 3. 1. scores["blue"] 2. scores["black"] 3. scores["red"] 4. scores["green"]
  4. 4. sizes["small"] = 4 → Changes a pair already there; sizes["huge"] = 9 → Adds a new pair; sizes["large"] = 1 → Changes a pair already there; sizes["tiny"] = 2 → Adds a new pair; sizes["medium"] = 7 → Changes a pair already there; sizes["giant"] = 6 → Adds a new pair
  5. 5. 45
  6. 6. 2
  7. 7. b) There is no such key, so there is no value for the dictionary to give back
  8. 8. 3

Looping over a dictionary

  1. 1. total = total + prices[k] → 30; total = total + 1 → 3; total = total + 2 → 6; total = prices[k] → 15; total = total + (prices[k] * 2) → 60
  2. 2. 12
  3. 3. blue
  4. 4. 7
  5. 5. 1. {"pen": 4, "bag": 2} 2. {"pen": 12, "bag": 3} 3. {"pen": 11, "bag": 40, "cup": 2} 4. {"pen": 15, "bag": 20, "cup": 30}
  6. 6. c) One of the keys
  7. 7. 2
  8. 8. 2

Writing and reading a file

  1. 1. 42
  2. 2. a) A list, with one piece of writing in it for each line of the file
  3. 3. bag
  4. 4. c) A piece of writing, which has to be turned into a number before it can be added to anything
  5. 5. 2
  6. 6. 2
  7. 7. 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
  8. 8. 3

Going through a file line by line

  1. 1. 2
  2. 2. a) The loop makes one more trip, and the total is 5 larger
  3. 3. 39
  4. 4. 17
  5. 5. 20
  6. 6. f = open("data.txt", "r") → Runs once, outside the loop; total = 0 → Runs once, outside the loop; total = total + int(line) → Runs once for every line in the file; print(int(line) * 2) → Runs once for every line in the file; f.close() → Runs once, outside the loop; print(total) → Runs once, outside the loop
  7. 7. 0
  8. 8. 4

Counting and adding with a condition

  1. 1. =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
  2. 2. b) Only the cells that say pen and nothing else
  3. 3. ">10" → Three cells pass; ">15" → Two cells pass; ">=20" → Two cells pass; ">=12" → Three cells pass; "<10" → Two cells pass; "<13" → Three cells pass
  4. 4. 15
  5. 5. 1. =COUNTIF(J1:J5, ">20") 2. =COUNTIF(J1:J5, "6") 3. =COUNTIF(J1:J5, ">=11") 4. =COUNTIF(J1:J5, ">5")
  6. 6. 5
  7. 7. b) A range of cells to look at, and a test that each of those cells either passes or fails
  8. 8. 3

Looking a value up in a table

  1. 1. 60
  2. 2. B3
  3. 3. "pen" → 14; "cup" → 31; "tin" → 22; "bag" → 9; "map" → 6
  4. 4. 55
  5. 5. 2
  6. 6. 10
  7. 7. 225
  8. 8. 1. =VLOOKUP("map", A1:B4, 2, FALSE) 2. =VLOOKUP("bag", A1:B4, 2, FALSE) 3. =VLOOKUP("pen", A1:B4, 2, FALSE) 4. =VLOOKUP("cup", A1:B4, 2, FALSE)

Sorting and filtering a sheet

  1. 1. 1. cup 2. pen 3. map 4. bag
  2. 2. map
  3. 3. 4
  4. 4. d) They are all back, exactly where they were — filtering never removed them from the sheet
  5. 5. 4
  6. 6. b) The amounts are in order, but each one now sits beside a name it never belonged to
  7. 7. More than 4 → 6; More than 25 → 2; More than 13 → 4; Less than 6 → 1; More than 20 → 3
  8. 8. cup

What a page is made of

  1. 1. 6
  2. 2. 5
  3. 3. 1
  4. 4. d) Each file has to be asked for separately, and every one of those asks takes its own time
  5. 5. 2
  6. 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. 7. 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
  8. 8. 5

Asking and answering over the web

  1. 1. 200 → Here is what you asked for; 404 → There is nothing here by that name; 301 → It has moved — ask again at this other address; 500 → Something went wrong at this end while I was answering; 403 → It is here, but you are not allowed to see it
  2. 2. c) The machine holding the page
  3. 3. 3
  4. 4. 3
  5. 5. c) It says how the request went — whether it worked, and if not, what sort of thing went wrong
  6. 6. b) Anybody who can see the address can read the answers, and the address can be saved or passed on exactly as it is
  7. 7. 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
  8. 8. 2

Tables, records and fields

  1. 1. 40
  2. 2. b) One record can no longer be picked out by giving its roll number alone
  3. 3. 47
  4. 4. 12
  5. 5.
    • 600
    • six hundred
  6. 6. 1. 4 records of 3 fields 2. 5 records of 4 fields 3. 2 records of 12 fields 4. 10 records of 3 fields
  7. 7. 31
  8. 8. 1

Asking a database a question

  1. 1. 2
  2. 2. 3
  3. 3. b) Every field, for every record that passed the condition
  4. 4. 48
  5. 5. 67
  6. 6. WHERE marks > 60 → 3; WHERE marks > 80 → 1; WHERE marks < 55 → 2; WHERE marks > 30 → 5; WHERE marks >= 51 → 4
  7. 7. WHERE marks > 60 → Decides which records come back; SELECT name, marks → Decides which fields come back; WHERE house = 'red' → Decides which records come back; SELECT roll → Decides which fields come back; WHERE marks < 40 → Decides which records come back; SELECT name, house, marks → Decides which fields come back
  8. 8. 35

Grade 10 Computer Science · www.arenapublications.com/learn