Advertisement
jspill

webinar-exam-review-2024-01-27

Jan 27th, 2024
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.87 KB | None | 0 0
  1. # Exam Review 2024 Jan 27
  2.  
  3. # Do those LABS
  4. # Ch 2-14... all Labs!
  5. # Ch 21-32 just ADDITIONAL LABS, but important practice!
  6. # get to know the Prac Tests, Ch 33 and 34... more than the Pre
  7.  
  8. # Use Submit Mode and get them to 100%!!!
  9. # PAY ATTENTION to the unit tests!
  10. # ... then UNIT TEST more! Unit test, unit test, unit test!
  11.  
  12. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  13. # Comp 2: Control Flow
  14. # Comp 3: Modules and Files
  15.  
  16. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  17.  
  18. # Operators
  19. # = # assigns a value
  20. # == # asking a question
  21. # +
  22. # -
  23. # *
  24. # /
  25. # % # modulo... whole number remainder... "how many whole things didn't fit since the last even division"
  26. # // # floor division... last even division
  27. # <
  28. # >
  29. # <=
  30. # >=
  31. # += # x+=1 --> x = x+1
  32. # -=
  33. # ** # compare to pow(), math.pow()
  34. # !=
  35. # # keywords
  36. # # in # if x in myList:
  37. # not # if not x in myList:
  38. # and
  39. # or # any one True means the combo is True... limit OR to 2-3 conditions
  40.  
  41. # Data Types/Classes
  42. # int
  43. # float
  44. # bool # True, False
  45. # str # ""
  46. # list # [ ]
  47. # dict # {key: value}
  48. # tuple # ( ) immutable, Python sees a,b,c as (a,b,c) --> return x,y --> return (x,y)
  49. # set # no duplicates, no order --> no indices, can't slice it, can't sort it, can't reverse
  50. # range # range()... container of consecutive numbers
  51. # file # open()... f.read(), f.readlines(), f.write()
  52.  
  53. # Comp 2
  54. # Control Flow! The how and when of our programs
  55. # IF statements...  if, if/else, if/elif, if/elif/else
  56. # LOOPS
  57. # WHILE - a general purpose loop, an IF that repeats
  58. # FOR - repeating action once for everything in a container
  59. # # Check out my For Loops webinar in The Gotchas
  60. # for ___ in __someContainer__:
  61. # for item in myList:
  62. # for char in myString:
  63. # for key in myDict:
  64. # for num in range():
  65. # for i in range(len(myList)): # for i in range(0, len(myList), 1)... "item" is myList[i]
  66. # for i, item in enumerate(myList):
  67.  
  68. # FUNCTIONS
  69. # defining/writing a function vs calling
  70. # modular... a function has ONE job
  71. # print/output or return (or maybe something else)
  72. # parameters are special variables for holding stuff coming into the function
  73. # parameters vs arguments
  74.  
  75. # def someFunction(x, y):
  76. #     return x + (2*y)
  77. #
  78. # if __name__ == "__main__": # is this script the one that's running now
  79. #     # inside this block we're answering this specific question
  80. #     input1 = int(input())
  81. #     input2 = int(input())
  82. #     myNum = someFunction(input1, input2)
  83. #     print(myNum)
  84.  
  85. # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
  86. # CodingBat also has good function-based Python questions:
  87. # https://codingbat.com/python
  88.  
  89. # BUILT-IN FUNCTIONS
  90. # input()
  91. # print()
  92. # len()
  93. # sum()
  94. # min()
  95. # max()
  96. # range()
  97. # list()
  98. # str()
  99. # dict()
  100. # tuple()
  101. # set()
  102. # enumerate()
  103. # round() # cousins math.ceil() and math.floor()
  104. # type() # print(type(myVar).__name__)
  105. # pow() # compare math.pow()
  106. # abs() # compare to math.fabs()
  107. # open() # for file objects
  108. # help() # help(str), help(str.isspace)
  109. # dir() # print(dir(str))
  110.  
  111. # STRINGS
  112. # be able to refer to indices, and slice
  113. # myStr = "abcdef"
  114. # # # mySlice[start:stop:step]
  115. # # revStr = myStr[::-1]
  116. # # print(revStr)
  117.  
  118. # KNOW YOUR WHITESPACE
  119. " " # space from spacebar
  120. # a lot of Unicode spaces
  121. "\n" # new line return... print() --> print(end="\n")
  122. "\r" # carriage return... back to beginning of the same line
  123. "\t" # tab
  124.  
  125. # STRING METHODS
  126. # myStr.format() # "Stuff I want to put together like {:.2f} and {}".format(myVar, myVar2)
  127. # myStr.strip() # input().strip()
  128. # myStr.split() # returns a list of smaller strings
  129. # ",".join(listOfStrings)
  130. # myStr.replace(subStr, newStr) # "remove" myStr = myStr.replace(subStr, "")
  131. # myStr.index(subStr), myStr.find(subStr) # return index where found
  132. # myStr.count(subStr) # return number of times subStr is there
  133. # case: .lower(), .upper(), .title(), .capitalize()
  134. # is/Boolean: .islower(), .isupper(), .isspace(), .isalpha(), .isalnum(), .isnumeric(), .isdigit()
  135. # myStr.startswith(subSTr), myStr.endswith(subStr)
  136.  
  137. # LISTS
  138. # be able to refer by index and to slice
  139. # LIST METHODS
  140. # +
  141. # myList.append(item)
  142. # myList.insert(i, item)
  143. # myList.extend(anotherList)
  144. # # -
  145. # myList.pop(i) # last one or by index
  146. # myList.remove(item) # pop() by index, remove() by value
  147. # myList.clear()
  148. # # other
  149. # myList.sort()
  150. # myList.reverse()
  151. # myList.count(item)
  152. # myList.copy()
  153. # myList.index(item)
  154.  
  155. # DICT
  156. # use the key like an index []... then you don't really need DICT methods
  157. # myDict[key] # get the value associated with that key --> takes the place of myDict.get()
  158. # myDict[key] = value # assigns new value to key --> similar to myDict.update({k:v})
  159.  
  160. # for key in myDict: # value is myDict[key]
  161. # if ___ in myDict: # check to see if a key is there before trying to get its value
  162.  
  163. # DICT METHODS
  164. # myDict.keys()
  165. # myDict.values()
  166. # myDict.items() # # for k, v in myDict.items()
  167.  
  168. # MODULES
  169. # math and csv
  170.  
  171. # MATH MODULE
  172. # import math # FULL IMPORT
  173. # math.factorial(x)
  174. # math.ceil(x)
  175. # math.floor(x)
  176. # math.sqrt(x)
  177. # math.pow(x, y)
  178. # math.fabs(x)
  179. # math.pi
  180. # math.e
  181.  
  182. # PARTIAL IMPORT
  183. # from math import sqrt # --> sqrt()
  184. # from math import ceil, floor # --> ceil(), floor()
  185. # from math import * # floor(), sqrt()
  186. #
  187. # # ALIAS IMPORT
  188. # import math as m
  189. # # m.floor(), m.fabs()
  190.  
  191. # FILES
  192. # modes: r, w, a
  193.  
  194. # READ MODE
  195. # with open("test.txt", "r") as f:
  196.     # f.read() # returns whole file as one big string
  197.     # f.readlines() # returns a list of strings, line by line
  198.     # f.write() # take one str arg and write into file (can't do here bc I'm in read mode)
  199. #     contents = f.readlines()
  200. #
  201. #
  202. # for line in contents:
  203. #     line = line.strip()
  204. #     print(line)
  205. # print(contents)
  206.  
  207. # CSV module
  208. # import csv # csv.reader()
  209. # with open("mock_data.csv", "r") as f1: # mockaroo.com
  210. #     contents = list(csv.reader(f1)) # # csv.reader(f, delimiter="\t")
  211. # print(contents[0:20]) # I'm slicing because I don't need to see all 1000 rows
  212.  
  213. # Side question: How to "create a dictionary" from a file?
  214. # ... there's really no such thing. You create a particular dictionary you want from particular data you have.
  215.  
  216. # Say we want a dictionary like this: myDict = {id: email}
  217. # myDict = {}
  218. # for line in contents[0:10]:
  219. #     # myDict[key] = value
  220. #     myDict[line[0]] = line[3]
  221. # print(myDict)
  222.  
  223. # k... back to files...
  224.  
  225. # WRITE MODE
  226. # with open("output_data33.csv", "w") as f2:
  227. #     # write out a file with every row where email ends in ".edu"
  228. #     for row in contents:
  229. #         # email is position 3 of inner list
  230. #         if row[3].endswith(".edu"):
  231. #             f2.write(','.join(row) + "\n")
  232.  
  233. # APPEND MODE
  234. # with open("append_to_this.txt", "r") as f3:
  235. #     print(f3.readlines())
  236. # with open("append_to_this.txt", "a") as f3:
  237.     # f3.write("\nPippin") # follow suit as needed based on what's in the file
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247. # APPEND MODE
  248.  
  249.  
  250.  
  251.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement