CSC108H1 Midterm: UTSG CSC 108 t2pm_solution

118 views4 pages
7 Mar 2019
School
Course
Professor
yifanyang and 39659 others unlocked
CSC108H1 Full Course Notes
21
CSC108H1 Full Course Notes
Verified Note
21 documents

Document Summary

Beside each code fragment below, show the output that it would create. If it would generate an error say so, and give the reason why. L = [1, 15, 4] for a in l: for b in l: print a + b. [1 mark] d = {9: 3, -3: 17, 40: 20} sum = 0 for x, y in d. items(): sum = sum + y print sum. 8 (b) the output depends on the order in which the key-value pairs are in the dictionary. But in all cases, 3 numbers will be printed and the final number will be 40. Suppose we want to know how many times an int at a certain position in a list occurs in a row. For example, with the list [55, 8, 14, 14, 14, 9, 0, 14, 14, 14, 14, 6] and the position 2, we would determine that the int 14 occurs 3 times in a row starting at that position.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents

Related Questions