{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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))
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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