Advertisement
jspill

webinar-exam-review-2024-02-17

Feb 17th, 2024
1,294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.01 KB | None | 0 0
  1. # Exam Review 2024 Feb 17
  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. # = # assignment
  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. # ** # pow(), math.pow()
  34. # !=
  35. # # keywords
  36. # in # membership check... if x in myList:
  37. # not # if not x in myList:
  38. # and
  39. # or # any one True would cause the combo is True... limit OR to 2-3 conditions
  40.  
  41. # Data Types/Classes
  42. # int
  43. # float
  44. # bool
  45. # str # ""
  46. # list # [ ]
  47. # dict # {key:value}, review Ch 4.5
  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 actions a known number of times -> once for everything in a container
  59. # FOR - repeating action once for everything in a container
  60. # # Check out my For Loops webinar in The Gotchas
  61. # for ___ in _someContainer_:
  62. # for item in myList:
  63. # for char in myStr:
  64. # for key in myDict: # value for that key in myDict[key]
  65. # for n in range():
  66. # for i in range(0, len(myList)): # for i in range(0, len(myList), 2)
  67. # for i, item in enumerate(myList):
  68.  
  69. # FUNCTIONS
  70. # defining/writing a function vs calling
  71. # modular... a function has ONE job
  72. # print/output or return (or maybe something else)
  73. # parameters are special variables for holding stuff coming into the function
  74. # parameters vs arguments
  75. #
  76. # def someFunction(x, y):
  77. #     return x - y
  78. #
  79. # if __name__ == "__main__": # is this script the one that's running now
  80. #     # inside this block we're answering this specific question
  81. #     input1 = int(input())
  82. #     input2 = int(input())
  83. #     myNum = someFunction(input1, input2)
  84. #     print(myNum)
  85.  
  86. # CodingBat also has good function-based Python questions:
  87. # https://codingbat.com/python
  88. # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
  89.  
  90. # BUILT-IN FUNCTIONS
  91. # input()
  92. # print()
  93. # len()
  94. # range()
  95. # int()
  96. # float()
  97. # list()
  98. # tuple()
  99. # dict()
  100. # str()
  101. # sum()
  102. # min()
  103. # max()
  104. # enumerate()
  105. # round() # cousins math.ceil() and math.floor()
  106. # pow() # cousin math.pow() and **
  107. # abs() # cousin math.fabs()
  108. # type() # print(type(x).__name__)
  109. # open() # for file object
  110. # help()
  111. # dir()
  112. # help(str) # help(str.isspace)
  113. # print(dir(str))
  114.  
  115. # STRINGS
  116. # be able to refer to indices, and slice
  117. # myStr = "abcd"
  118. # # mySlice[start:stop:step]
  119. # revStr = myStr[::-1]
  120. # print(revStr)
  121.  
  122. # KNOW YOUR WHITESPACE
  123. " " # space from spacebar
  124. # a lot of Unicode spaces
  125. "\n" # new line return
  126. "\r" # carriage return
  127. "\t" # tab
  128.  
  129. # unless otherwise stated... printed output should end a new line return... 99% of the time it does anyway
  130. print("hey") # --> print("hey", end="\n")
  131. # we only need to change that when...
  132. #1 ... this specific says to do something else
  133. #2 ... you yourself overrode the end parameter of print() as the last thing you did... just call print() again
  134.  
  135. # STRING METHODS
  136. # myStr.format() # "Stuff I want put this {} and {} together in one string".format(var1, var2)
  137. # myStr.strip() # input().strip()
  138. # myStr.split() # returns a list of smaller strings
  139. # ",".join(listOfStrings)
  140. # myStr.replace(subStr, newStr) # "remove" myStr = myStr.replace(subStr, "")
  141. # myStr.index(subStr), myStr.find(subStr) # returns index where first found
  142. # myStr.count(subStr) # return # of times its there
  143. # case: .lower(), .upper(), .title(), .capitalize()
  144. # is/Boolean: .islower(), .isupper(), .isspace(), .isalpha(), .isnumeric(), .isdigit(), .isalnum()
  145. # myStr.startswith(subStr), myStr.endswith(subStr)
  146.  
  147. # LISTS
  148. # be able to refer by index and to slice
  149. # LIST METHODS
  150. # +
  151. # myList.append(item)
  152. # myList.insert(i, item)
  153. # myList.extend(anotherList)
  154. # # -
  155. # myList.pop(i) # last one or by index
  156. # myList.remove(item) # pop() by index, remove() by value
  157. # myList.clear()
  158. # # other
  159. # myList.sort()
  160. # myList.reverse()
  161. # myList.count(item) # returns # times its there
  162. # myList.copy()
  163. # myList.index(item)
  164.  
  165. # DICT
  166. # use the key like an index []... then you don't really need DICT methods
  167. # myDict[key] # get the value for that key
  168. # myDict[key] = value # assigns new value to key
  169.  
  170. # DICT METHODS
  171. # myDict.keys() # all dict keys in a set-like object
  172. # myDict.values() # all dict values in a set-like object
  173.  
  174. # # check if key in dict
  175. # if ___ in myDict: # checking keys
  176. # # check if value in dict
  177. # if ___ in myDict.values() # check values... but I don't know what key :(
  178. # # check if value and get key
  179. # # ... you'd have to for loop and check one by one
  180.  
  181. # MODULES
  182. # math and csv
  183.  
  184. # MATH MODULE
  185. # import math # FULL IMPORT
  186. # math.factorial(x)
  187. # math.ceil(x)
  188. # math.floor(x)
  189. # math.sqrt(x)
  190. # math.pow(x, y) # do not confuse with math.exp()
  191. # math.fabs(x)
  192. # math.pi
  193. # math.e
  194. #
  195. # # PARTIAL IMPORT
  196. # from math import sqrt # --> sqrt()
  197. # from math import ceil, floor # --> ceil(), floor()
  198. # from math import * # floor(), sqrt()
  199. #
  200. # # ALIAS IMPORT
  201. # import math as m
  202. # # m.floor(), m.ceil()
  203. #
  204.  
  205. # FILES
  206. # modes: r, w, a
  207.  
  208. # READ MODE
  209. # myInput = input() # filename from input
  210. # with open(myInput, "r") as f:
  211. # with open("test.txt", "r") as f:
  212. #     # f.read()  # returns whole file as one big string
  213. #     # f.readlines() # returns a list of strings, line by line
  214. #     # f.write() # take one str arg and write into file (can't do here bc I'm in read mode)
  215. #     contents = f.readlines()
  216. # print(contents)
  217. # for line in contents:
  218. #     line = line.strip()
  219. #     print(line)
  220.  
  221. # CSV module
  222. import csv # csv.reader()
  223. with open("mock_data.csv", "r") as f1: # mockaroo.com
  224.     contents = list(csv.reader(f1)) # csv.reader(f1, delimiter="\t")
  225. # print(contents)
  226. # for row in contents[0:25]:
  227. #     print(row)
  228.  
  229. # WRITE MODE
  230. # with open("output_data34.csv", "w") as f2:
  231. #     # write out a file with each row where last name is Hicklingbottom
  232. #     for row in contents:
  233. #         # last name is row[2]
  234. #         if row[2] == "Hicklingbottom":
  235. #             f2.write(",".join(row) + "\n")
  236.  
  237. # APPEND MODE
  238. # with open("append_to_this.txt", "r") as f3:
  239. #     print(f3.readlines())
  240. with open("append_to_this.txt", "a") as f3:
  241.     f3.write("\nPippin")
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement