final exam crib sheet.docx

6 Pages
Unlock Document

Simon Fraser University
Computing Science
CMPT 120
Diana Cukierman

Final Exam Crib Sheet Adrian de Leon 301208324 Basic Commands new1new1stri new2new2 ddecimal in string new3new3wordinew4 sinserta stringprint new1 new2 new3 new4 gfloating point number82f314159Example abcXdeXfg Xabcdefg314chXwordabcXdeXfg new The result takes up eight spaces with two digits after the decimal for i in rangelenword point if not wordi chnewnewwordiprint newnew String CommandsIndexingn Example abcXdeXfg Xabcdefg Concatenation chXwordabcXdeXfgnew Repetition for i in rangelenword Len length of string if not wordi chnewnewwordi Methods for strings print newnew Astringcenterastring with size aAstringcountitemnumber of occurrences of an itemExchanging variables Astringuppercapitalized Using auxiliary variable Astringlowerlower case letters auxvar1var1var2var2aux Astringfinditemindex of first occurrenceShifting 4 variables Find character in string v4v3v3v2v2v1v10 for i in rangelenstif stich Shifting 4 variables circularly print found chch in position i auxv4v4v3 else v3v2v2v1 print did not find it v1aux Finding total times character is in string Create matrix with all 0s but different rows foundFalse row0n total0 lolfor i in rangelenst for i in rangen if stich rowrowfoundTrue lolappendrow if foundtotaltotal1 Print first row of a matrix else dimlenmatrix totaltotalfor c in rangedim return total print matrix0c tFinding first occurrenceCreate a list of list and a square matrix with n rows and n foundFalse columns n input from user for i in rangelenst def initSquareMatrix8n if stich and foundFalse counter0 print this is the first time we found ch in posi lol foundTrue for r in range0n else rowprint not here or first time for c in range0ncountercounter1 Generating strings rowappendcounternew1new2new3new4wordabcdlolappendrow for i in 123 return lol
More Less

Related notes for CMPT 120

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.