← Back to Class 10 Computer Science

Term pack

Class 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.

Class 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.A list holds four values, and a program runs the line values[4] = 7. Why is that a mistake?

    • a) There is no position 4 yet, and writing to a position can only change a value that is already there
    • b) The list would end up five values long with a gap in the middle of it
    • c) Position 4 is the first position, and it already holds a value
    • d) Writing to a position is never allowed once a list has been made
  2. 2.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])
  3. 3.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])
  4. 4.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))
  5. 5.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(7)
    • box.append(12)
    • box[3] = 1
    • box[2] = 9
    • box.append(0)
  6. 6.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))
  7. 7.One value is added on the end of this list. What number does the program print?

    queue = [4, 9]
    queue.append(6)
    print(len(queue))
  8. 8.A list holds five values. One of its values is written over, and then one more value is added on the end. How many values does the list hold now?

    • a) 4
    • b) 6
    • c) 7
    • d) 5

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

Class 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.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"])
  2. 2.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"])
  3. 3.A dictionary called counts holds {"pen": 4, "book": 9, "bag": 2, "map": 7, "cup": 6}. Match each piece of code to the number it gives.

    • counts["book"]
    • counts["map"]
    • counts["pen"]
    • counts["cup"]
    • len(counts)
    • 7
    • 9
    • 4
    • 6
    • 5
  4. 4.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"])
  5. 5.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))
  6. 6.The dictionary is measured rather than looked in. What does this program print?

    stock = {"red": 4, "blue": 7, "green": 2, "black": 9}
    print(len(stock))
  7. 7.One line here both reads a value and writes one back under the same key. What does this program print?

    totals = {"north": 30, "south": 12}
    totals["south"] = totals["south"] + 8
    print(totals["south"])
  8. 8.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))

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

Class 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.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)
  2. 2.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)
    • 15
    • 6
    • 60
    • 3
    • 30
  3. 3.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])
  4. 4.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)
  5. 5.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)
  6. 6.Nothing is looked up in this loop at all — the counter climbs by one however large the values are. What does the program print?

    counts = {"red": 3, "blue": 8, "green": 1, "black": 6}
    n = 0
    for key in counts:
        n = n + 1
    print(n)
  7. 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. 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 · Class 10 Computer Science · www.arenapublications.com/learn

Class 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.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)
  3. 3.A program reads a file of several lines using readlines(). What does readlines() hand back?

    • a) One long piece of writing with the whole file in it
    • b) A dictionary, with the line numbers as its keys
    • c) A list, with one piece of writing in it for each line of the file
    • d) A number saying how many lines the file holds
  4. 4.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()
  5. 5.A file already holds several lines. A program opens it with "w" and then closes it again without writing anything at all. What does the file hold now?

    • a) Everything it held before, with a blank line added on the end
    • b) Nothing at all
    • c) Everything it held before, since nothing was written
    • d) One blank line where the writing used to be
  6. 6.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))
  7. 7.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))
  8. 8.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
    • Close the file
    • Open the same file again with "r"
    • Open the file with "w"
    • Read the lines back out

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

Class 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.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)
  2. 2.The numbers out of this file are collected into a list as they are read. What does the program print?

    f = open("data.txt", "w")
    f.write("6\n11\n4\n")
    f.close()
    values = []
    f = open("data.txt", "r")
    for line in f:
        values.append(int(line))
    f.close()
    print(values[1])
  3. 3.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.

    • "2\n3\n"
    • "9\n"
    • "1\n1\n1\n1\n"
    • "6\n8\n"
  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.Only some of these lines reach the total. What does the program print?

    f = open("takings.txt", "w")
    f.write("5\n40\n8\n30\n")
    f.close()
    total = 0
    f = open("takings.txt", "r")
    for line in f:
        if int(line) >= 30:
            total = total + int(line)
    f.close()
    print(total)
  6. 6.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) The number of the line, counting from 0
    • c) The whole file, all at once
    • d) One line of the file, as a piece of writing
  7. 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. 8.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(int(line) * 2)
    • total = total + int(line)
    • f.close()
    • total = 0
    • f = open("data.txt", "r")
    • print(total)

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

Class 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 the words D1 = pen, D2 = bag, D3 = pen, D4 = cup and D5 = pen. What number does this formula show?

    =COUNTIF(D1:D5, "pen")
  2. 2.What are the two things a COUNTIF is given?

    • a) A test, and the number of cells that ought to pass it
    • b) A range of cells to look at, and a test that each of those cells either passes or fails
    • c) A range of cells, and the number that the cells in it are expected to add up to
    • d) Two ranges of cells, the second saying which of the first to count
  3. 3.A sheet holds E1 = 10, E2 = 10 and E3 = 4. Read the comparison in the test very carefully. What number does this formula show?

    =COUNTIF(E1:E3, ">10")
  4. 4.A COUNTIF over the eight cells H1:H8, with the test ">50", shows 3. How many of those eight cells hold 50 or less?

  5. 5.A sheet holds C1 = 4, C2 = 15, C3 = 9 and C4 = 20. What number does this formula show?

    =SUMIF(C1:C4, ">=10")
  6. 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
    • 34
    • 4
    • 2
  7. 7.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) Only the cells that say pen and nothing else
    • d) The cells sitting in the same rows as the cells that say pen
  8. 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 · Class 10 Computer Science · www.arenapublications.com/learn

Class 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.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)
  2. 2.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("cup", A1:B4, 2, FALSE)
    • =VLOOKUP("bag", A1:B4, 2, FALSE)
    • =VLOOKUP("map", A1:B4, 2, FALSE)
  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
    • 14
    • 6
    • 9
    • 22
  4. 4.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)
  5. 5.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)
  6. 6.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"
    • "hat"
    • "jug"
    • "tin"
    • "bag"
  7. 7.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 shows an answer one row further down than it should
    • b) It works, because a lookup searches the whole sheet anyway
    • c) It shows the price in B2, since that is the first row of the range
    • d) Nothing is found, because the row holding pen is not inside the range the formula was given
  8. 8.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)

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

Class 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.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

    • Narrowing a filter so that fewer rows show
    • Sorting by a second column where the first one ties
    • Switching a filter off again
    • Sorting by a column, largest first
    • Sorting by a column, smallest first
    • Filtering to show only some of the rows
  2. 2.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) Nothing has gone wrong — the rest of each row is carried along automatically
    • b) The names in column A have been put in order as well
    • c) The amounts are in order, but each one now sits beside a name it never belonged to
    • d) The sheet refuses to sort until the whole of it is selected
  3. 3.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
    • 6
    • 2
    • 1
    • 3
    • 4
  4. 4.A sheet's five rows hold 18, 4, 27, 11 and 9 in column B. The rows are sorted by column B, smallest first. Counting the top row as row 1, which row does the 18 end up in?

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

  8. 8.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

Sorting and filtering a sheet · Class 10 Computer Science · www.arenapublications.com/learn

Class 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 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?

  2. 2.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 name of a picture
    • A photograph on the page
    • The picture that name refers to
    • The words of a paragraph
    • The stylesheet
    • A heading
  3. 3.Match each page to the number of files a browser has to fetch to show the whole of it.

    • HTML and nothing else
    • HTML and one stylesheet
    • HTML, one stylesheet and two pictures
    • HTML and six pictures
    • HTML, two stylesheets and three pictures
    • 2
    • 1
    • 7
    • 4
    • 6
  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.Why must a browser fetch the HTML file before it can fetch any of the others?

    • a) The HTML is always the largest of the files, and the largest has to go first
    • b) The names of the other files are inside it, so until it arrives the browser does not know what else to ask for
    • c) The other files cannot be stored until the HTML has been stored
    • d) The machine holding the page sends them in that order and will not send them in any other
  6. 6.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?

  7. 7.What is actually inside the HTML file that a browser fetches first?

    • a) Only a list of the other files, and none of the words
    • b) The page's words and how they are arranged, together with the names of the other files it needs
    • c) The pictures, with the words kept in a separate file
    • d) Everything the page shows, pictures included, all in the one file
  8. 8.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?

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

Class 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.An address ends with the piece shown below. How many name-and-value pairs is it carrying?

    ?topic=lists&sort=new&page=3
  2. 2.A browser asks for a page and the answer that comes back is 500. Whose end has the problem?

    • a) The browser that asked
    • b) The reader's own connection
    • c) The machine holding the page
    • d) Nobody's — 500 means the page is there but empty
  3. 3.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?

  4. 4.Match each status number to what the answer carrying it is saying.

    • 200
    • 404
    • 301
    • 500
    • 403
    • Here is what you asked for
    • It has moved — ask again at this other address
    • There is nothing here by that name
    • It is here, but you are not allowed to see it
    • Something went wrong at this end while I was answering
  5. 5.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?

  6. 6.Put these addresses in order of how many name-and-value pairs each one carries, fewest first.

    • /find?q=pen
    • /notices/exam/timetable?term=summer&stream=science
    • /s?a=1&b=2&c=3
    • /search?item=pen&size=large&count=4&page=2
  7. 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. 8.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?

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

Class 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 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?

  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) The table can no longer be sorted by any of its fields
    • c) The other records lose their roll numbers
    • d) One record can no longer be picked out by giving its roll number alone
  3. 3.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
  4. 4.A school keeps one record for each pupil. Sort each field by whether it could be that table's primary key.

    Groups: Could be the primary key · Could not be the primary key

    • First name
    • Roll number
    • Admission number
    • Date of birth
    • Email address
    • House
  5. 5.Match each word to what it names in a database table.

    • Record
    • Field
    • Primary key
    • Table
    • Value
    • All the records of one kind, kept together
    • One row: everything the table holds about one thing
    • What one field holds in one record
    • One column: one particular piece of information, asked of every row
    • The field whose value is never repeated in two records
  6. 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. 7.A table has five fields and a hundred and twenty records. How many single pieces of information does it hold altogether?

  8. 8.What is a primary key for?

    • a) It is whichever field happens to be the first column of the table
    • b) It is the field the table is kept sorted by
    • 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 password that has to be given before the table will open

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

Class 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 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?

  3. 3.The answer to a query comes back as twelve rows of four columns. How many single values are in that answer?

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

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

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

Answer keys — Class 10 Computer Science

In the same order as the worksheets.

Changing and growing a list

  1. 1. a) There is no position 4 yet, and writing to a position can only change a value that is already there
  2. 2. 20
  3. 3. 18
  4. 4. 3
  5. 5. 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
  6. 6. 5
  7. 7. 3
  8. 8. b) 6

Dictionaries and their keys

  1. 1. 45
  2. 2. 30
  3. 3. counts["book"] → 9; counts["map"] → 7; counts["pen"] → 4; counts["cup"] → 6; len(counts) → 5
  4. 4. 14
  5. 5. 3
  6. 6. 4
  7. 7. 20
  8. 8. 2

Looping over a dictionary

  1. 1. 17
  2. 2. total = total + prices[k] → 30; total = total + 1 → 3; total = total + 2 → 6; total = prices[k] → 15; total = total + (prices[k] * 2) → 60
  3. 3. 7
  4. 4. 12
  5. 5. 2
  6. 6. 4
  7. 7. 15
  8. 8. 2

Writing and reading a file

  1. 1. 42
  2. 2. 21
  3. 3. c) A list, with one piece of writing in it for each line of the file
  4. 4. 2
  5. 5. b) Nothing at all
  6. 6. 2
  7. 7. 3
  8. 8. 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

Going through a file line by line

  1. 1. 0
  2. 2. 11
  3. 3. 1. "1\n1\n1\n1\n" 2. "2\n3\n" 3. "9\n" 4. "6\n8\n"
  4. 4. 17
  5. 5. 70
  6. 6. d) One line of the file, as a piece of writing
  7. 7. 2
  8. 8. 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

Counting and adding with a condition

  1. 1. 3
  2. 2. b) A range of cells to look at, and a test that each of those cells either passes or fails
  3. 3. 0
  4. 4. 5
  5. 5. 35
  6. 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. 7. c) Only the cells that say pen and nothing else
  8. 8. 3

Looking a value up in a table

  1. 1. 225
  2. 2. 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)
  3. 3. "pen" → 14; "cup" → 31; "tin" → 22; "bag" → 9; "map" → 6
  4. 4. 7
  5. 5. 25
  6. 6. "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
  7. 7. d) Nothing is found, because the row holding pen is not inside the range the formula was given
  8. 8. 2

Sorting and filtering a sheet

  1. 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. 2. c) The amounts are in order, but each one now sits beside a name it never belonged to
  3. 3. More than 4 → 6; More than 25 → 2; More than 13 → 4; Less than 6 → 1; More than 20 → 3
  4. 4. 4
  5. 5. map
  6. 6. 1. cup 2. pen 3. map 4. bag
  7. 7. 4
  8. 8. box

What a page is made of

  1. 1. 70
  2. 2. 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
  3. 3. HTML and nothing else → 1; HTML and one stylesheet → 2; HTML, one stylesheet and two pictures → 4; HTML and six pictures → 7; HTML, two stylesheets and three pictures → 6
  4. 4. d) Each file has to be asked for separately, and every one of those asks takes its own time
  5. 5. b) The names of the other files are inside it, so until it arrives the browser does not know what else to ask for
  6. 6. 5
  7. 7. b) The page's words and how they are arranged, together with the names of the other files it needs
  8. 8. 4

Asking and answering over the web

  1. 1. 3
  2. 2. c) The machine holding the page
  3. 3. 2
  4. 4. 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
  5. 5. 1
  6. 6. 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
  7. 7. 11
  8. 8. 3

Tables, records and fields

  1. 1. 31
  2. 2. d) One record can no longer be picked out by giving its roll number alone
  3. 3. b) One teacher's name in every pupil's record, so most of the names are stored many times over
  4. 4. Roll number → Could be the primary key; First name → Could not be the primary key; Admission number → Could be the primary key; Date of birth → Could not be the primary key; Email address → Could be the primary key; House → Could not be the primary key
  5. 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. 6. 75
  7. 7.
    • 600
    • six hundred
  8. 8. c) It is the field whose value is different in every record, so that any one record can always be picked out

Asking a database a question

  1. 1. 2
  2. 2. 67
  3. 3. 48
  4. 4. a) Which records come back
  5. 5. 3
  6. 6. 35
  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. 1. WHERE marks > 85 2. WHERE marks > 70 3. WHERE marks > 60 4. WHERE marks > 40

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