Created
October 12, 2018 03:12
-
-
Save Squishy123/a6a45f7799d9e18d9c7bb49b10e00e1b to your computer and use it in GitHub Desktop.
My Solutions for CPS109 Midterms Practice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def q1(): | |
| file='C:\\Users\\Christian\\Documents\\Projects\\CPS109\\resources\\mediasources\\beach.jpg' | |
| picture=makePicture(file) | |
| return getRed(getPixelAt(picture, 100, 100)) | |
| print q1() | |
| def q2(): | |
| return ord('e') | |
| print q2() | |
| def q3(): | |
| return chr(ord('z')+1) | |
| print q3() | |
| def sumOrds(string): | |
| sum=0 | |
| for ch in string: | |
| sum+=ord(ch) | |
| return sum | |
| print sumOrds('abcdefghijklmnopqrstuvwxyz') | |
| def catChrs(stringOfDigits): | |
| alpha="abcdefghijklmnopqrstuvwxyz" | |
| str="" | |
| for ch in stringOfDigits: | |
| str += alpha[int(ch)] | |
| return str | |
| print catChrs('05443106') | |
| def sumRed(picture, n): | |
| sum=0 | |
| for p in range(0, min(n, len(getPixels(picture)))): | |
| sum+=getRed(getPixels(picture)[p]) | |
| return sum | |
| print sumRed(makePicture('C:\\Users\\Christian\\Documents\\Projects\\CPS109\\resources\\mediasources\\beach.jpg'), 50) | |
| def sumRedByIndex(picture, index1, index2): | |
| sum=0 | |
| for p in range(index1, index2): | |
| sum+=getRed(getPixels(picture)[p]) | |
| return sum | |
| print sumRedByIndex(makePicture('C:\\Users\\Christian\\Documents\\Projects\\CPS109\\resources\\mediasources\\beach.jpg'), 50, 60) | |
| def flipCase(string): | |
| flip="" | |
| for ch in string: | |
| if(ch.islower()): | |
| flip+=ch.upper() | |
| elif(ch.isupper()): | |
| flip+=ch.lower() | |
| return flip | |
| print flipCase('WinchESteR 3CaThEDraL!') | |
| def mirror2(string): | |
| mir="" | |
| for ch in string: | |
| mir = ch * 2 + mir + ch * 2 | |
| return mir | |
| print mirror2('This is a dog!') | |
| def encode2(string, key): | |
| alpha="abcdefghijklmnopqrstuvwxyz" | |
| alphamod=alpha | |
| for k in key: | |
| alphamod=alphamod.replace(k, "") | |
| alter=alphamod[0:5] + key + alphamod[5:len(alphamod)] | |
| cipher="" | |
| for ch in string: | |
| if alpha.find(ch) == -1: | |
| cipher+=alter[len(alter)-1] | |
| else: | |
| cipher+=alter[alpha.find(ch)] | |
| return cipher | |
| print encode2('goodolddays', 'blue') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 160 | |
| 101 | |
| { | |
| 2847 | |
| afeedbag | |
| 462 | |
| 141 | |
| wINCHesTErcAtHedRAl | |
| !!ggoodd aa ssii ssiihhTTTThhiiss iiss aa ddoogg!! | |
| lnnfnjffayr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment