Directions • Printyournameande-mailIDinthebelowboxrightnow. • Printyournameande-mailIDonthelastpagerightnow. • Enteryoursignatureinthebelowboxaftercompletingthetest. Name: E-mailID: Onmyhonor,IpledgethatIhaveneithergivennorreceivedhelponthistest. Signature: Testrules • Printyourname,id,andpledgeasrequested. • Thispledgedexamisclosedtextbook.Theonlydeviceyoumayaccessduringthetestisyourown laptop. • Youarenotallowedtoaccessclassexamplesoryourownpastassignmentsduringthetest;i.e.,theonly Pythoncodeyoumayaccessorviewareonesthatyoudevelopforthistest. • TheonlywindowsthatcanbeopenonyourcomputerarePyCharmandasinglebrowserwithtabsonly opentotheclasswebsite. • • PyCharmcanbeusedonlyfordevelopingtheprogramstobesubmitted.Itcannotbeusedfortheshort answerquestions. Programsshoulddemonstrateproperprogrammingstyle;e.g.,headercomments,whitespace,identifier naming,etc. • Whetheraprogramcompilesisimportant. CS1112Fall2015Test1–Page 1 of 8 1. (10points)Supposethefollowingassignmentsareineffect. r=range(2,6) s=[31,41] t=[41,59] u=['AB','C','D','EF'] v=['AB','CD'] w=['CS',1112] x='CS1112' a. Whatisthefirstvalueinranger? b. Whatisthelastvalueinranger? c. Canthesecondvalueinrangerbe changed(yesorno)? d. Canthesecondvalueinlistsbe changed(yesorno)? e. Whatisthevalueofs+t? f. Whatisthevalueof('B'inu)? g. Whatisthevalueofuafter delu[1:3]? h. Whatisthevalueofvafter v.reverse()? i. IswalegalPythonlist(yesorno)? j. Whatlistisproducedbyx.split()? CS1112Fall2015Test1–Page 2 of 8 2. (10points)Supposesisavariablerepresentingthestring'ABCABCABCABC' s A B C A B C A B C 0 1 2 3 4 5 6 7 8 9 a. Whatisthelengthofs? b. Whatistheindexofthefirst occurrenceof'C'? c. Whatstringisproducedbythe slicings[3:6]? d. Whatstringisproducedby s.replace('C','')? e. Whatisthevalueof s.find('b')? f. Whatisthevalueof s.rfind('C',7)? g. Whatsliceofsisneededto producethestring'CA'? h. Howmanyelementsareinthe listproducedbys.split()? i. Whatisthevalueofsafter s.lower()? j. Whatisthevalueof s.capitalize()? CS1112Fall2015Test1–Page 3 of 8 A B C 10 11 12 3. (1points)Whattypeofvalueisprintedbythefollowingcodesegment? importrandom r=random.randrange(0,2) print(r) 4. (3points)Whatarethepossiblevaluesprintedbythefollowingcodesegment? importrandom r=random.randrange(1,3) print(r) 5. (3points)Isitpossibleforthefollowingcodesegmenttoprintthesamevaluetwice(yesorno)? importrandom r1=random.randrange(1,3) r2=random.randrange(1,3) print(r1,r2) 6. (3points)Isitpossibleforthefollowingcodesegmenttoprinttwodifferentvalues(yesorno)? importrandom random.seed(1112) r1=random.randrange(1,3) random.seed(1112) r2=random.randrange(1,3) print(r1,r2) CS1112Fall2015Test1–Page 4 of 8 7. (1point)Whatisthevalueof1+1*4? 8. (1point)Whatisthedifferencebetween thecalculationsx/yandx//y? 9. (1point)Supposeyisanumericvariable. WriteaBooleanexpressionthatistrueif thevalueofyisabirthyearforamember of the millennial generation (i.e., y lies inclusivelybetween1980and1996). 10. (1point)Writeastatementthatsetspto thevalue !"#$ !!"# ! . 11. (1point)Considerthebelowcodesegment. Whatisthemin(x)? x=['12','2','9','11'] y=[12,2,9,11] Whatisthemin(y)? 12. (1point)Considerthebelowcodesegment. Whatist’stype? s='wahoo3' t,u=s.split() Whatisu’stype? 13. (1point)Supposerisastring containingonlybase10digits.Givean assignmentstatementthatconvertsr tothecorrespondingnumericvalue. 14. (1point)Thecircumferencecofa circleis2 π r.Writethecorresponding Pythonstatement. CS1112Fall2015Test1–Page 5 of 8 15. (20points)Developprogramone.py.Theprogramgetsanintegerinputvaluen.Theprogramprints n 1112 .Thereshouldbenootheroutput. Threesampleruns Enteraninteger:3 1375036928 Enteraninteger:1 1112 Enteraninteger:4 1529041063936 16. (20points)Developprogramtwo.py.Theprogramgetsthenameofawebfileasinput.Thewebfileis locatedintheCS1112webfolder http://www.cs.virginia.edu/~cs1112/datasets/testing/ The web file will contain two numbers x and y. The program determines and prints the relationship betweenxandy;thatisequal,ascending,ordescending.Thereshouldbenootheroutput. Somesampledatafilesareavailable(wewillusedifferentfilesduringtesting). • a.txtcontains31and41. • b.txtcontains11and11. • c.txtcontains20and15. Threesampleruns Enternameofwebfile:a.txt ascending Enternameofwebfile:b.txt equal Enternameofwebfile:c.txt descending CS1112Fall2015Test1–Page 6 of 8 17. (20points)Developprogramthree.py.Theprogramgetstwoinputs.Thefirstinputisastring.The secondinputisalineofwords.Theprogramprintsthewordsonthelinethatcontainthestring.There shouldbenootheroutput. When matching, case does not matter. For example, 'abc' matches 'daBChick', and 'XY' matches 'epoxy'. Threesampleruns Enterword:stir Enterlistofwords:Thesoupwasre-stirredwithSTirLINGstirrups re-stirred STirLING stirrups Enterword:abc Enterlistofwords:TheEnglishalphabetgoesfromatoz Enterword:DeF Enterlistofwords:Thedefendant'sreasoningwasindefensible defendant's indefensible CS1112Fall2015Test1–Page 7 of 8 Clearlyprintyournameande-mailid Name E-mailID: Page2 _________________________________________________ 10 Page3 _________________________________________________ 10 Page4 _________________________________________________ 10 Page5 _________________________________________________ 10 one.py _________________________________________________ 20 two.py _________________________________________________ 20 three.py _________________________________________________ 20 Total _________________________________________________ 100 CS1112Fall2015Test1–Page 8 of 8