Advertisement
jspill

webinar-exam-review-v4-2023-03-16

Mar 16th, 2024
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.74 KB | None | 0 0
  1. # Exam Review 2024 Mar 16
  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. # Operators
  21. # = # assignment
  22. # == # asking a question
  23. # +
  24. # -
  25. # *
  26. # /
  27. # % # modulo... whole number remainder... "how many whole things didn't fit since the last even division?"
  28. # // # floor division... last even division
  29. # <
  30. # >
  31. # <=
  32. # >=
  33. # += # x += 1 --> x = x+1
  34. # -=
  35. # ** # pow(), math.pow()
  36. # !=
  37. # # keywords
  38. # in # membership check... if x in myList:
  39. # not # if not x in myList:
  40. # and
  41. # or # any one True would cause the combo is True... limit OR to 2-3 conditions
  42.  
  43. # Data Types/Classes
  44. # int
  45. # float
  46. # bool
  47. # str # ""
  48. # list # [ ]
  49. # dict # {key: value}, review Ch 4.5
  50. # tuple # ( ) immutable, Python sees x,y,z as (x,y,z) -> return a,b,c --> return (a,b,c)
  51. # set # {x,y,z} no duplicates, no order --> no indices, can't slice it, can't sort it, can't reverse it
  52. # range # range()... container of consecutive numbers
  53. # file # open()... f.read(), f.readlines(), f.write()
  54.  
  55. # Comp 2
  56. # Control Flow! The how and when of our programs
  57. # IF statements... if, if/else, if/elif, if/elif/else
  58. # LOOPS
  59. # WHILE - a general purpose loop, an IF that repeats
  60. # FOR - repeating action once for everything in a container
  61. # FOR - repeating actions a known number of times -> once for everything in a container
  62. # Check out my For Loops webinar in The Gotchas
  63. # for ___ in _someContainer_:
  64. # for item in myList:
  65. # for char in myStr:
  66. # for key in myDict: # value for that key in myDict[key]
  67. # for n in range(5):
  68. # for i in range(0, len(myList)):
  69. # for i, item in enumerate(myList):
  70.  
  71. # FUNCTIONS
  72. # defining/writing a function vs calling it
  73. # modular... a function has ONE job
  74. # output/print vs return (or maybe something)
  75. # parameters are special variables for holding stuff coming into the function
  76. # parameters vs arguments
  77. #
  78. # def someFunction(x, y):
  79. #     return x ** y
  80. #
  81. # if __name__ == "__main__": # is this script the one that's running now
  82. #     input1 = int(input())
  83. #     input2 = int(input())
  84. #     myNum = someFunction(input1, input2)
  85. #     print(myNum)
  86.  
  87. # final "task" page of Ch 10, 11, 13, 14
  88. # CodingBat also has good function-based Python questions:
  89. # https://codingbat.com/python
  90.  
  91. # BUILT-IN FUNCTIONS
  92. # input()
  93. # print()
  94. # range()
  95. # pow()
  96. # type() # print(type(myVar).__name__)
  97. # list()
  98. # str()
  99. # int()
  100. # float()
  101. # len()
  102. # sum()
  103. # min()
  104. # max()
  105. # enumerate()
  106. # open()
  107. # round() # cousins math.ceil(), math.floor()
  108. # abs() # math.fabs(), "magnitude"
  109. # help()
  110. # dir() # # print(dir(str))
  111. # help(str) # help(str.isspace)
  112.  
  113. # STRINGS
  114. # be able to refer to indices, and slice
  115. # myStr = "abcdef"
  116. # # mySlice[start:stop:step]
  117. # revStr = myStr[::-1]
  118. # print(revStr)
  119.  
  120. # KNOW YOUR WHITESPACE
  121. # " " # space from spacebar
  122. # # a lot of Unicode spaces
  123. # "\n" # new line return
  124. # "\t" # tab
  125. # "\r" # carriage return
  126.  
  127. # myVar = input().strip()
  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() after that block
  134.  
  135. # STRING METHODS
  136. # myStr.format() # "Stuff I want to put this {} and {} together in a string".format(val1, val2)
  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) # return index location
  142. # myStr.count(subStr) # returns number of times it's there
  143. # case: lower(), upper(), title(), capitalize()
  144. # is/Boolean: isspace(), isupper(), islower(), isalpha(), isnumeric(), isdigit(), isalnum()
  145. # myStr.startswith(subStr), 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 int count of item
  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 the keys
  176.  
  177. # MODULES
  178. # math and csv
  179.  
  180. # MATH MODULE
  181. # import math # FULL IMPORT
  182. # math.factorial(x)
  183. # math.ceil(x)
  184. # math.floor(x)
  185. # math.sqrt(x)
  186. # math.pow(x, y)
  187. # math.fabs(x)
  188. # math.pi
  189. # math.e
  190. #
  191. # # PARTIAL IMPORT
  192. # from math import ceil # just ceil(), no math.
  193. # from math import factorial, sqrt # factorial(), sqrt()
  194. # from math import * # floor(), sqrt()
  195. #
  196. # # ALIAS IMPORT
  197. # import math as m
  198. # m.floor(), m.ceil()
  199.  
  200. # FILES
  201. # modes: r, w, a
  202.  
  203. # READ MODE
  204. # filename = input()
  205. with open("test.txt", "r") as f:
  206.     # f.read()  # returns whole file as one big string
  207.     # f.readline() # singular! I stay away from this one
  208.     # f.readlines()  # returns a list of strings, line by line
  209.     # f.write() # take one str arg and write into file (can't do here bc I'm in read mode)
  210.     contents = f.readlines()
  211. # print(contents)
  212. # for line in contents:
  213. #     line = line.strip()
  214. #     print(line)
  215.  
  216. # CSV module
  217. import csv # csv.reader()
  218. with open("mock_data.csv", "r") as f1: # mockaroo.com
  219.     # contents = f1.readlines()
  220.     contents = list(csv.reader(f1)) # csv.reader(f1, delimiter="\t")
  221.  
  222. # print(contents)
  223.  
  224. # WRITE MODE
  225. # with open("output_data35.csv", "w") as f2:
  226. #     # write out a file from contents where emails are from Yahoo
  227. #     for row in contents:
  228. #         # email is row[3]
  229. #         if row[3].endswith("@yahoo.com"):
  230. #             f2.write(",".join(row) + "\n")
  231.  
  232. # APPEND MODE
  233. # with open("append_to_this.txt", "r") as f3:
  234. #     print(f3.readlines())
  235. with open("append_to_this.txt", "a") as f3:
  236.     f3.write("\nPippin")
  237.  
  238.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement