CSC108H1 Midterm: UTSG CSC 108 summer2011_sol
yifanyang and 39659 others unlocked
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 12 - 4. 0*3 + 2. [1 mark] z = 3 * "blah" print z + str(3) + "blah" [1 mark] ratio = 1. 5433333 print "ratio is %. 4f", % (ratio) [1 mark] s = "abc" for c in s: piece = "" for i in range(4): piece = c * i + ":" print piece. [1 mark] s = "abc" for i in range(2): piece = "" for c in s: piece = piece + str(i) + c * i print piece. Solution: (a) 3 (b) 2. 0 or 2 and some indication that it"s a float. (c) blahblahblah3blah (d) ratio is 1. 453 (e) aaa: bbb: ccc: (f) Each of the code sequences below runs without error. The next page is provided for your rough work.