Midterm 2 Practice

Midterm 2 Practice - !"#$%&$'()&*%'"+(,(...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
" !"#$%&$' )&*%'"+ ,, "#$""% &'()* +++++++++++++++++++++++++++++++ ,-./0 12 3%"" ,45.)6 78* +++++++++++++++++++++++++++++++ 9)'5 '00 :; <=) ;:00:6/4> /4;:.('</:4 ?);:.) @<'.</4> <=) )A'(* B=/@ C9,DB7DE (/5<).( /@ 4:< ()'4< <: ?) ' -).;)F< .)-.)@)4<'</:4 :; <=) G-F:(/4> (/5<).(H B=/@ -.'F</F) )A'( 6'@ 4:< ('5) <: ?) '00$/4F0G@/I)J K:G '.) @</00 .)@-:4@/?0) ;:. L4:6/4> '00 ('<)./'0 G- <: '45 /4F0G5/4> M:()6:.L N* B)<./@J B=/@ )A'( 6/00 0/L)0O ?) 0:4>). <='4 <=) 'F<G'0 (/5<).(J 9)'5 /4@<.GF</:4@ F'.);G00O '45 @=:6 '00 6:.LJ P=:.< '4@6). QG)@</:4@ @=:G05 ?) '4@6).)5 ?./);0O2 ?G< F:(-0)<)0OJ R:. @:0G</:4@2 '<<)45 ' D,$0)5 .)I/)6 @)@@/:42 :. F:4<'F< O:G. D,J S:@< :; <=) QG)@</:4@ F:() ;.:( -'@< )A'(@ '45 QG/TT)@J B=).);:.) /< /@ -:@@/?0) ;:. '4O :; <=)@) QG)@</:4@ :. @:()<=/4> :; @/(/0'. 0)I)0 <: F:() G- /4 O:G. (/5<).( 3J U::5 0GFLH B:<'0 C:/4<@* "1% !"#$%&"'()* ,-. ./"# 01"2.3 4 /&5( 21. #((2 ./( (6&' 0&0() 7(.8 9/()(:1)( ./( ;"::"$<%.7 %(5(% '&7 5&)7 =<. ./"# 0)&$."$( #/1<%; /(%0 71< .1 ";(2.":7 >/"$/ .10"$# 71< 2((; '1)( :1$<# 12? @ -2;)(
Background image of page 1

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

View Full DocumentRight Arrow Icon
3 -.*' /"#$&012 745/F'<) 6='< <=) ;:00:6/4> F:5) 6/00 -./4< V 5.'6 34 AB 01"2.#C a = [4, 2, 6, 1, 5] j = 0 for i in range (len(a)-1, -1, -2): a[j] += a[i] j += 1 print a 54 AB 01"2.#C z = 251 s = “z” + str(z) while (z > len(s)): z /= len(s) s += str(z) print z, “,”, s 64 AB 01"2.#C def mystery(x, y, depth=0): print " "*depth, "mystery(", x, ",", y, ")" if ((x < y) or (y <= 0)): pass # do nothing else: mystery(x/y, y-1, depth+1) mystery(x/5, y/2, depth+1) mystery(13, 4) 74 AB 01"2.#C # Assuming that all of the other functions are written, # canvas.data.width = 200, canvas.data.height = 150, # and redrawAll() is called in init() def redrawAll() k = 2 h = canvas.data.height w = canvas.data.width px = [] py = [] for x in range (0, w, 50): for y in range (h/k, h, h/k): px += [x] py += [y] canvas.create_polygon(px[0],py[0],px[2],py[2],px[3],py[3],\ fill=“black”,outline =“black”,width=5)
Background image of page 2
W )89%'"8 -.*'2 X='< 5: <=)@) ;G4F< /:4@ 5:Y P<'<) 6='< )'F= :; <=) ;: 0 0:6 /4> ;G4F</:4@ 5:)@ /4 >)4).'02 /4 ' ;)6 6:.5@ :; -0'/4 E4>0/@=J K:G (G@< /5)4</;O <=) >)4).'0 -'<<).4 '45 @=:G05 4:< @<'<) 0/4) ?O 0/4) 6='< )'F= @<)- :; <=) ;G4F</:4 5:)@J :4 AB 01"2.#C # Assume ls is a list def mysteryA(ls): if len(ls) == 0: return [[]] else: r = [] h = [] for x in ls: if x not in h: ts = ls[:] ts.remove(x) for p in mysteryA(ts): r.append([x]+p) h.append(x) return r ;4 AB 01"2.#C # a and b are lists with single-digit integers as elements def mysteryB(a, b): while (len(a) < len(b)): a.insert(0, 0) while (len(b) < len(a)): b.insert(0, 0) r = [0] * len(a) c = 0 for i in range(len(a)):
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

Midterm 2 Practice - !&quot;#$%&amp;$'()&amp;*%'&quot;+(,(...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online