CSC108H1 Midterm: UTSG CSC 108 2010_winter_sol

19 views20 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. [1 mark] print 24 - 12 / 4 - 2. [1 mark] z = "over" + "and" print "" + z * 3 + "" [1 mark] avg = 87. 28196 print "average is %. 2f percent", % (avg) [1 mark] s = "ya" for c in s: piece = "" for i in range(4): piece = piece + c * i + ":" print piece. [1 mark] s = "no" for i in range(4): piece = "" for c in s: piece = piece + c * i + ":" print piece. Solution: (a) -3 (b) 19 (c) overandoverandoverand (d) average is 87. 28 percent (e) Assume we have a game board consisting of n positions, and two objects: the hero and the enemy. (the game board has only one row. )