Advertisement
jspill

webinar-exam-review-2024-03-23

Mar 23rd, 2024
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.59 KB | None | 0 0
  1. # Exam Review 2024 Mar 23
  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. # When you've gotten the Ch 33-34 Prac Tests to 100, go back and do each again.
  13. # This time, try to think of 2-3 more unit tests that could be run on each question.
  14.  
  15. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  16. # Comp 2: Control Flow
  17. # Comp 3: Modules and Files
  18.  
  19. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  20.  
  21. # Operators
  22. # = # assignment
  23. # == # asking a question... result in Boolean value
  24. # +
  25. # -
  26. # *
  27. # /
  28. # % # modulo... whole number remainder... "how many whole things didn't fit since the last even division?"
  29. # // # floor division... the last even division
  30. # <
  31. # >
  32. # <=
  33. # >=
  34. # += # x += 1 --> x = x + 1
  35. # -=
  36. # ** # similar to pow() and math.pow()
  37. # !=
  38. # # keywords
  39. # in # membership check... if x in myList:
  40. # not # if not x in myList:
  41. # and
  42. # or # any one True would cause the combo to be True... limit OR to 2-3 conditions
  43.  
  44. # Data Types/Classes
  45. # int
  46. # float
  47. # bool
  48. # str # ""
  49. # list # [ ]
  50. # dict # {key:value}
  51. # tuple # ( ) immutable, Python sees a, b, c as (a,b,c) --> return x,y --> return (x,y)
  52. # set # { } no duplicate values, no order --> no indices, can't slice it, can't sort it or reverse
  53. # range # range()... container of consecutive numbers
  54. # file # open()... f.read(), f.readlines(), f.write()
  55.  
  56. # Comp 2
  57. # Control Flow! The how and when of our programs
  58. # IF statements... if, if/else, if/elif, if/elif/else
  59. # LOOPS
  60. # WHILE - a general purpose loop, an IF that repeats
  61. # FOR - repeating actions a known number of times --> once for everything in a container
  62. # FOR in Python is explicitly for a container
  63. # # Check out my For Loops webinar in The Gotchas
  64. # for ___ in _someContainer_:
  65. # for item in myList:
  66. # for char in myStr:
  67. # for key in myDict: # myDict[key]
  68. # for n in range(0, 5): # [0, 1, 2, 3, 4]
  69. # for i in range(len(myList)): # for i in range(0, len(myList), 2):
  70. # for i, item in enumerate(myList):
  71.  
  72. # FUNCTIONS
  73. # defining/writing a function vs calling
  74. # modular... a function has ONE specific job
  75. # print/output or return (or maybe something else)
  76. # parameters are special variables for holding stuff coming into the function
  77. # parameters vs arguments
  78. #
  79. # def someFunction(x, y):
  80. #     return (x*y) - y
  81. #
  82. # if __name__ == "__main__": # is this script the one that's running now
  83. #     # inside this block we're answering this specific question
  84. #     input1 = int(input())
  85. #     input2 = int(input())
  86. #     myNum = someFunction(input1, input2)
  87. #     print(myNum)
  88. #
  89.  
  90. # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
  91. # CodingBat also has good function-based Python questions:
  92. # https://codingbat.com/python
  93.  
  94. # Built-In Functions
  95. # input()
  96. # print()
  97. # range()
  98. # len()
  99. # sum()
  100. # min()
  101. # max()
  102. # int()
  103. # float()
  104. # list()
  105. # type() # myVar = 3.14, print(type(myVar).__name__)
  106. # enumerate()
  107. # pow()
  108. # abs() # cousin math.fabs()
  109. # round() # cousins math.ceil(), math.floor()
  110. # open()
  111. # help() # help(str) # help(str.isspace)
  112. # dir() # print(dir(list))
  113.  
  114. # STRINGS
  115. # be able to refer to indices, and slice
  116. # myStr = "abcdefg"
  117. # # mySlice[start:stop:step]
  118. # revStr = myStr[::-1]
  119. # print(revStr)
  120.  
  121. # KNOW YOUR WHITESPACE
  122. " " # space from the spacebar
  123. # a lot of other spaces in Unicode
  124. "\n" # new line return
  125. "\r" # carriage return
  126. "\t" # tab
  127.  
  128. # unless otherwise stated... printed output should end a new line return...
  129. # 99% of the time it already does
  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 {:formattingInstructions} 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) # index int or raises an error if not there
  142. # myStr.find(subStr) # index int or -1
  143. # myStr.count(subStr) # return int number of times it's there
  144. # case: .lower(), .upper(), .title(), .capitalize()
  145. # is/Boolean: .islower(), .isupper(), .isspace(), .isalpha(), .isnumeric(), .isdigit(), .isalnum()
  146. # print("ashes of mars".title()) # Ashes Of Mars
  147. # myStr.startswith(subStr), myStr.endswith(substr)
  148.  
  149. # LISTS
  150. # be able to refer by index and to slice
  151. # LIST METHODS
  152. # +
  153. # myList.append(item)
  154. # myList.insert(i, item)
  155. # myList.extend(anotherList)
  156. # # -
  157. # myList.pop(i) # pop() by index
  158. # myList.remove(item) # remove() by value
  159. # myList.clear()
  160. # # other
  161. # myList.sort()
  162. # myList.reverse()
  163. # myList.count(item) # returns num occurrences
  164. # myList.copy()
  165. # myList.index(item)
  166.  
  167. # DICT
  168. # use the key like an index []... then you don't really need DICT methods
  169. # myDict[key] # get the value for that key... like myDict.get()
  170. # myDict[key] = value # assigns new value to key, replaces myDict.update({key:value})
  171.  
  172. # DICT METHODS
  173. # myDict.keys() # all dict keys in a set-like objects
  174. # myDicts.values() # all dict values in a set-like object
  175.  
  176. # membership check
  177. # if ___ in myDict: # looking at keys
  178. # if ___ in myDict.values() # looking at values
  179.  
  180. # MODULES
  181. # math and csv
  182.  
  183. # MATH MODULE
  184. # import math # FULL IMPORT
  185. # math.factorial(x)
  186. # math.ceil(x)
  187. # math.floor(x)
  188. # math.sqrt(x)
  189. # math.pow(x, y)
  190. # math.fabs(x)
  191. # math.pi
  192. # math.e
  193.  
  194. # PARTIAL IMPORT
  195. # from math import ceil # just ceil() not math.ceil()
  196. # from math import ceil, floor # ceil(), floor()
  197. # from math import * # floor(), sqrt()
  198. #
  199. # # ALIAS IMPORT
  200. # import math as m # m.floor(), m.factorial()
  201.  
  202. # FILES
  203. # modes: r, w, a
  204.  
  205. # READ MODE
  206.  
  207. # myInput = input() # filename from input
  208. # with open(myInput, "r"):
  209. # with open("test.txt", "r") as f:
  210. #     # f.read() # return the whole file as one string
  211. #     # f.readlines() # returns a list of strings, line by line
  212. #     # f.write() # writes a single str arg to file
  213.  
  214. # with open("test.txt", "r") as f:
  215. #     contents = f.readlines()
  216. # # print(contents) # ['Hello.\n', 'This\n', 'is\n', 'just\n', 'a\n', 'string.\n', 'But...\n', 'with\n', 'many\n', 'line\n', 'breaks!']
  217. # for line in contents:
  218. #     line = line.strip()
  219. #     print(line)
  220.  
  221. # import csv
  222. # # csv.reader()
  223. # with open("mock_data.csv", "r") as f1: # mockaroo.com
  224. #     # contents = f.readlines()
  225. #     contents = list(csv.reader(f1)) # csv.reader(f1, delimiter="\t") for tsv
  226. # # print(contents)
  227. # for row in contents[0:20]:
  228. #     print(row)
  229. # print(contents[3][2])
  230.  
  231. # WRITE MODE
  232. # write out a new file where all the last names begin with "H"
  233. # with open("output_data36.csv", "w") as f2:
  234. #     for row in contents:
  235. #         # ['1', 'Remington', 'Shilling', 'rshilling0@wsj.com', 'Male', '1.71.141.52']
  236. #         # last name is row[2]
  237. #         # if row[2][0] == "H":
  238. #         # if row[2][0].lower() == "h":
  239. #         if row[2].startswith("H") or row[2].startswith("h"):
  240. #             f2.write(",".join(row) + "\n")
  241.  
  242. # APPEND MODE
  243. # reading it to see...
  244. # with open("append_to_this.txt", "r") as f3:
  245. #     print(f3.readlines())
  246.  
  247. # write it...
  248. with open("append_to_this.txt", "a") as f3:
  249.     f3.write("\nPippin")
  250.    
  251. # read it back to check...
  252. with open("append_to_this.txt", "r") as f3:
  253.     print(f3.readlines())
  254.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement