Dictionaries
Lists
XML
Syntax
Random
Tuples
100

Consider the following dictionary:

dict = { 'aardvark' : 'anthony', 'buffalo' : 'boris', 'zebra' : 'zelda' }

What would be the out of the following:

dict['aardvark']

'anthony'

100

What is the out of the following?

>>>a[100, 30, 20]
>>>a

100, 30, 20

100

True or false, we need to import a method before we can parse XML files in Python.

True, we need to import ElementTree:

from xml.etree.ElementTree import *

100

What is wrong with the following function?

def addOne(number): print number + 1

Everything is one line / there is no block indentation.

100

What would be the output of the following?

False

100

Can len() be used with tuples?  If so, why would you use it?

Yes, it would tell you the number of items in a tuple.

200

True or False:

each key in a dictionary must be unique

True

200

What is the output of the following?

>>>a[100, 30, 20]
>>>a[2]

20

200

Explain what a DTD file is and what is is used for.

A DTD (document type definition) file is a text file that specifies elements and attributes used in an XML document.

200

Which is correct?

if (x==2):
  print "yes"

if (x=2):
  print "yes"

The first, 

if (x==2):
  print "yes"

200

What is wrong with the following command entered at the console?

The context of the variable 'a' is only valid inside the function.

200

Consider the following tuple:

t = (0, 1, 2, 3, 4)

what would be the result of the follwoing?

t + (5, 6)

(0, 1, 2, 3, 4, 5, 6)

300

True or False:

—Each key must be of a mutable type.

False, each key in a dictionary must be an immutable type.

300

Describe the code needed to set a list variable a that would store the values 100 and 20

>>> a[100, 20]

300

What is the following an example of?

A DTD file.

300

Write on the board the correct syntax to write "My Web Page" in the title of an HTML page.  You only need to write the title tag, the rest of the HTML document can be assumed.

<title>My Web Page</title>

300

True or False:

A string is an immutable ordered collection of characters.

True - variable names can change, but the string itself is immutable (unchangeable).  

300

Consider the following tuple.  

t = (0, 1, 2, 3, 4)

what would be the output of the following?

t[-3]

2

the [-3] represents an index counting backwards from the end of the tuple.

400

Given the following dictionary, could you change the value corresponding to first key, 5?  If so, how would you do this?

d = { 5:50, 9:90 }

Yes!

d[5] = 55

400

What is the output of the following?

>>>a['green', 'eggs', 'ham']
>>>a[0] * 3

greengreengreen

400

Review the following DTD file.  How could you write this file if you chose to not use attributes in your XML?

400

Write on the board the correct HTML syntax to insert an image (flower1.jpg) into your page.  You only need to write the image tag, the rest of the HTML document can be assumed.

<image src="flower1.jpg">

400

What would the following function do?

This would increase the volume of an audio file passed to it.

400

What is the difference between a tuple and a list?

The main difference between lists and a tuples is the fact that lists are mutable whereas tuples are immutable.

500

Consider the following dictionary:

dict = { 'aardvark' : 'anthony', 'buffalo' : 'boris', 'zebra' : 'zelda' }

What would be the output of:

dict.keys()

['aardvark', 'buffalo', 'zebra']

500

a[2] = a[2] + 23

500

Carefully examine the following XML and DTD file.  Is this XML file valid?  Why or why not?

No! It should look like the following representing the attributes properly:

500

Write on the board the syntax for declaring that a document is written in HTML (hint: the type of document).  

<!DOCTYPE html>

500

Consider the following function.  What would mystery(3) print?

3

2

1

500

What would the result be for the following set of statements?

TypeError: 'tuple' object does not support item assignment

Because t is a tuple which cannot be changed.