Advertisement
jspill

webinar-python-exam-review-2023-01-20

Jan 20th, 2024
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.57 KB | None | 0 0
  1. # Exam Review 2024 Jan 20
  2.  
  3. # Do those LABS
  4. # Ch 2-14... all Labs!
  5. # Ch 21-32 just ADDITIONAL LABS, but important practice!
  6. # 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. # Operators
  18. # = # assigns
  19. # == # asking a question? A condition
  20. # +
  21. # -
  22. # *
  23. # /
  24. # % # modulo... whole number remainder... "how many whole things didn't fit since the last even division?"
  25. # // # floor division... the last even division
  26. # <
  27. # >
  28. # <=
  29. # >=
  30. # += # x += 1 ... x = x + 1
  31. # -=
  32. # ** # compare to pow(), math.pow()
  33. # !=
  34. # # keyword
  35. # in # if x in myList
  36. # not # if not x in myList
  37. # and
  38. # or # any one True means the combo is True...limit OR to 2-3 conditions
  39.  
  40. # Data Types/Classes
  41. # int
  42. # floats
  43. # bool # True, False
  44. # str # ""
  45. # list # [ ]
  46. # dict # {key: value}
  47. # tuple # ( ) immutable, Python see a,b,c as (a,b,c) --> return x,y --> return (x,y)
  48. # set # { } no duplicates, unordered --> no index, no slicing, no sort, no reverse
  49. # range # range()... container of consecutive numbers --> range(start, stop, step)
  50. # file # open()... f.read(), f.readlines(), f.write()
  51.  
  52. # Comp 2
  53. # Control Flow! The how and when of our programs
  54. # IF statements... if, if/else, if/elif, if/elif/else, etc
  55. # LOOPS
  56. # WHILE - - an IF that repeats
  57. # FOR - looping over a container, or known number of times... hence range()
  58. # # Check out my For Loops webinar in The Gotchas
  59. # for ___ in __someContainer__:
  60. # for item in myList:
  61. # for char in myStr:
  62. # for key in myDict: # myDict[key]
  63. # for n in range(5):
  64. # for i in range(0, len(myList)): # myList[i]
  65. # for i, item in enumerate(myList):
  66.  
  67. # FUNCTIONS
  68. # defining/writing a function vs calling
  69. # modular... a function has ONE job
  70. # return statements
  71. # parameters are special variables for holding stuff coming into the function
  72. # parameters vs arguments
  73. # pay attention to whether the function is asked to return or print()/output
  74. #
  75. # def someFunction(x, y):
  76. #     return x // 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. # min()
  94. # max()
  95. # sum()
  96. # pow()
  97. # abs()
  98. # round() # cousins math.floor() and math.ceil()
  99. # enumerate()
  100. # int()
  101. # float()
  102. # list()
  103. # range()
  104. # str()
  105. # dict()
  106. # tuple()
  107. # chr()
  108. # ord()
  109. # open()
  110. # sorted() # different from list.sort()
  111. # reversed() # different from list.reverse()
  112. # type() # print(type(myVar).__name__)
  113. # help()
  114. # dir()
  115. # help(str)
  116. # print(dir(str))
  117. # help(str.isspace)
  118.  
  119. # STRINGS
  120. # be able to refer to indices, and slice
  121. # mySlice[start:stop:step]
  122. # myStr = "abcd"
  123. # revStr = myStr[::-1]
  124. # print(revStr)
  125.  
  126. # KNOW YOUR WHITESPACE
  127. # " " # space from spacebar
  128. # # a lot of Unicode spaces
  129. # '\n' # new line return
  130. # "\t" # tab
  131. # "\r" # carriage return
  132.  
  133. # STRING METHODS
  134. # myStr.format() # "Stuff I want to put together in this string like {:.2f}".format(myVar)
  135. # myStr.strip() # input().strip()
  136. # myStr.split() # returns a list of smaller strings
  137. # ",".join(listOfStrings)
  138. # myStr.replace(subStr, newStr) # remove myStr = myStr.replace(subStr, "")
  139. # myStr.index(subStr), myStr.find(subStr) # return index where found
  140. # myStr.count(subStr) # return number of occurrences
  141. # case: myStr.lower(), myStr.upper(), myStr.capitalize(), myStr.title()
  142. # is/Boolean: myStr.islower(), myStr.isspace(), myStr.isalpha(), myStr.isdigit(), myStr.isnumeric(), myStr.isalnum()
  143. # myStr.startswith(subStr), myStr.endswith(subStr)
  144.  
  145. # LISTS
  146. # be able to refer by index and to slice
  147. # LIST METHODS
  148. # +
  149. # myList.append(item)
  150. # myList.insert(i, item)
  151. # myList.extend(anotherList)
  152. # -
  153. # myList.pop(i)
  154. # myList.remove(item) # pop() by index, remove() by value
  155. # myList.clear()
  156. # # other
  157. # myList.sort()
  158. # myList.reverse()
  159. # myList.count(item)
  160. # myList.index(item)
  161.  
  162. # DICT
  163. # # use the key like an index []... then you don't really need DICT methods
  164. # myDict[key] # get the value for that key --> similar to myDict.get()
  165. # myDict[key] = value # assigns new value to key --> similar to myDict.update({k:v})
  166. # DICT METHODS
  167. # myDict.keys()
  168. # myDict.values()
  169. # if "this" in myDict: # membership check on a dict looks at keys
  170. # if "that" in myDict.values():
  171. # myDict.items() # for k, v in myDict.items()
  172.  
  173. # MODULES
  174. # math and csv
  175.  
  176. # MATH MODULE
  177. # import math # "full import"
  178. # math.factorial(x)
  179. # math.ceil(x)
  180. # math.floor(x)
  181. # math.sqrt(x)
  182. # math.pow(x, y)
  183. # math.fabs(x)
  184. # math.pi
  185. # math.e
  186.  
  187. # PARTIAL IMPORT
  188. # from math import sqrt # --> sqrt()
  189. # from math import floor, ceil --> floor(), ceil()
  190. # from math import * # floor(), sqrt()
  191.  
  192. # ALIAS IMPORT
  193. # import math as m # --> m.floor(), m.factorial()
  194.  
  195. # FILES
  196. # modes: r, w, a
  197.  
  198. # READ MODE
  199. # with open("test.txt", "r") as f:
  200. #     # f.read() # returns whole file as one big string
  201. #     # f.readlines() # returns a list of strings, line by line
  202. #     # f.write() # take one str arg and write into file (can't do here bc I'm in read mode)
  203. #     contents = f.readlines()
  204.  
  205. # for line in contents:
  206. #     line = line.strip()
  207. #     print(line) # print(line, end="\n")
  208. # print(contents)
  209.  
  210. # CSV Module
  211. import csv # csv.reader()
  212. with open("mock_data.csv", "r") as f1: # mockaroo.com
  213.     contents = list(csv.reader(f1)) # csv.reader(f1, delimiter="\t") if a tsv
  214. # print(contents[0:20])
  215.  
  216. # WRITE MODE
  217. # let's write out a file with just rows where the last name started with H
  218. # with open("output_data32.csv", 'w') as f2:
  219. #     for row in contents:
  220. #         # last name is position 2... row[2]
  221. #         # lastName = row[2]
  222. #         if row[2].startswith("H") or row[2].startswith("h"):
  223. #         # if row[2].lower().startswith("h"):
  224. #         # if row[2][0].lower() == "h":
  225. #             f2.write(",".join(row) + "\n")
  226.  
  227. # APPEND MODE
  228. # with open("append_to_this.txt", "r") as f3:
  229. #     print(f3.readlines())
  230.  
  231. # ['Frodo\n', 'Sam\n', 'Merry'] # no final line return in this file tells me how to end my file's last line
  232. with open("append_to_this.txt", "a") as f3:
  233.     f3.write("\nPippin")
  234.  
  235.  
  236.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement