final.examples

# final.examples - ECS 10 Concepts of Computation Example...

This preview shows pages 1–3. Sign up to view the full content.

ECS 10 Concepts of Computation Example Final Problems 1. Here is a little program, not necessarily correct. ages= {} ages["cat"]=4 if 4 in ages: print ages[4] This program will. .. a) print cat b) print 4 c) run without error, but not print anything. d) cause an error, because we cannot use the string cat as a list index. e) cause an error, because we cannot use the integer 4 as a dictionary key. Answer: c. ages is a dictionary. Anything can be used as a dictionary key. But there is only one thing in this dictionary, stored under the key "cat" . There is nothing stored under the key 4 . 2. The following code will crash. Why? bird = ’awk’ letters = [] for char in bird: letters = letters + char a. The for loop does not include a range function. b. The variable letters is not correctly initialized. c. The variable char was not initialized at all. d. You cannot concatenate a list and a string. e. It should be letters == letters+char Answer: d. The variable char contains a character, but letters is a list. 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
3. After executing this line, x = 5 which of the following expressions have the value True? 1. (not (x > 9)) and (x > 6) 2. not ((x > 9) and (x > 6)) 3. (not (x > 9)) or (x > 6) 4. not ((x > 9) or (x > 6)) a) 1, 2 and 3 b) 2, 3 and 4 c) 2 and 4 d) 2 and 3 e) 1 and 4 Answer: b. 1 is True and False == False, 2 is not (False and False) == True, 3 is True or False == True, and 4 is not (False or False), which is True. 4. The following program is not necessarily correct.
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/14/2008 for the course ECS 10 taught by Professor Amenta during the Fall '07 term at UC Davis.

### Page1 / 7

final.examples - ECS 10 Concepts of Computation Example...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online