Advertisement
jspill

webinar-exam-review-2024-04-20

Apr 20th, 2024
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.40 KB | None | 0 0
  1. # Exam Review 2024 Apr 20
  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. # Data Types/Classes
  22. # int
  23. # float
  24. # bool # True, False
  25. # str # ""
  26. # list # [ ]
  27. # dict # {key:value}
  28. # tuple # ( ) immutable, Python sees a,b,c as (a,b,c) --> return x,y,z --> return (x,y,z)
  29. # set # { } no duplicate values, no order --> no indices, can't slice it, can't sort it or reverse
  30. # range # range()... container of consecutive numbers
  31. # file # open()... f.read(), f.readlines(), f.write()
  32.  
  33. # Operators
  34. # = # assigns a value
  35. # == # asking a question... result in Boolean value
  36. # +
  37. # -
  38. # *
  39. # /
  40. # % # modulo... whole number remainder... "how many things didn't fit since the last even division?"
  41. # // # floor division... the last even division
  42. # <
  43. # >
  44. # >=
  45. # <=
  46. # += # x += 1 --> x = x + 1
  47. # -=
  48. # ** # similar to pow() and math.pow()
  49. # !=
  50. # # keywords
  51. # in # membership check... if x in myList
  52. # not # if not x in myList:
  53. # and
  54. # or # any one True would cause the combo to be True... limit OR to 2-3 conditions
  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 the container
  62. # FOR in Python is explicitly about a container: list, etc
  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: # for key, value in myDict.items()... or if k is the key, the value for that key is myDict[k]
  68. # for n in range(0, someNum):
  69. # for i in range(0, len(myList)):
  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
  81. #
  82. # if __name__ == "__main__":  # is this script the one that's running?
  83. #     input1 = int(input())
  84. #     input2 = int(input())
  85. #     myNum = someFunction(input1, input2)
  86. #     print(myNum)
  87.  
  88. # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
  89. # CodingBat also has good function-based Python questions:
  90. # https://codingbat.com/python
  91.  
  92. # Built-In Functions
  93. # input()
  94. # print()
  95. # float()
  96. # int()
  97. # str()
  98. # range()
  99. # len()
  100. # sum()
  101. # min()
  102. # max()
  103. # type() # myVar = "hi", print(type(myVar).__name__)
  104. # enumerate()
  105. # pow()
  106. # abs() # cousin math.fabs()
  107. # round() cousins math.ceil(), math.floor()
  108. # open()
  109. # help()# help(str), help(str.isspace)
  110. # dir() # print(dir(str))
  111.  
  112. # STRINGS
  113. # be able to refer to indices, and to slice
  114. # myStr = "abcd"
  115. # # mySlice[start:stop:step]
  116. # revStr = myStr[::-1]
  117. # print(revStr)
  118.  
  119. # KNOW YOUR WHITESPACE
  120. " " # space from spacebar
  121. # a lot of other spaces
  122. "\n" # new line return
  123. "\t" # tab
  124. "\r" # carriage return
  125.  
  126. # unless otherwise stated... printed output should end a new line return...
  127. # 99% of the time it already does
  128. # print("hey") --> print("hey", end="\n")
  129. # we only need to change that when...
  130. #1 ... this specific says to do something else
  131. #2 ... you yourself overrode the end parameter of print() as the last thing you did... just call print() again after the loop
  132.  
  133. # STRING METHODS
  134. # myStr.format() # "Stuff I want to put {:formatting instr} and {:.2f} into my string".format(var1, var2)
  135. # myStr.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) # return int index where found, or raise error
  140. # myStr.find(subStr)  # return int index where found, or -1
  141. # myStr.count(subStr) # return int count of how many times it's there
  142. # case: .lower(), .upper(), .title(), .capitalize()
  143. # is/Boolean: .islower(), .isupper(), .isspace(), .isalpha(), .isnumeric(), .isdigit(), .isalnum()
  144. # myStr.startswith(subStr), myStr.endswith(subStr)
  145.  
  146. # LISTS
  147. # be able to refer by index and to slice
  148. # LIST METHODS
  149. # +
  150. # myList.append(item)
  151. # myList.insert(i, item)
  152. # myList.extend(anotherList)
  153. # # -
  154. # myList.pop(i) # pop() by index
  155. # myList.remove(item) # remove() by value
  156. # myList.clear()
  157. # # other
  158. # myList.sort()
  159. # myList.reverse()
  160. # myList.count(item) # returns num of times it's there
  161. # myList.index(item)
  162. # myList.copy()
  163.  
  164. # DICT
  165. # use the key like an index []... then you don't really need DICT methods
  166. # myDict[key] # get the value of that key
  167. # myDict[key] = value # assign a new value to key
  168. #
  169. # # membership check
  170. # # if ___ in myDict: # looking at keys
  171. #
  172. # # DICT METHODS
  173. # myDict.keys() # all dict keys in a set-like object
  174. # myDict.values() # all dict values in a set-like object
  175.  
  176. # MODULES
  177. # math and csv
  178.  
  179. # MATH MODULES
  180. # import math # FULL IMPORT
  181. # math.factorial(x)
  182. # math.ceil(x)
  183. # math.floor(x)
  184. # math.sqrt(x)
  185. # math.pow(x, y)
  186. # math.fabs(x)
  187. # math.pi
  188. # math.e
  189.  
  190. # # PARTIAL IMPORT
  191. # from math import ceil # just ceil() not math.ceil()
  192. # from math import sqrt, floor # sqrt(), floor()
  193. # from math import * # factorial(), floor(), but no math
  194. #
  195. # # ALIAS IMPORT
  196. # import math as m # m.floor(), m.ceil()
  197.  
  198. # FILES
  199. # modes: r, w, a
  200.  
  201. # READ MODE
  202. # filename = input()
  203. # with open(filename, "r") as f:
  204. # with open("plain_text_file.txt", "r") as f:
  205.     # f.read() # returns the whole file as one big string
  206.     # f.readlines() # returns a list of strings, each line is one string
  207.     # f.write(someStr) # writes a single str arg to file
  208.  
  209. # with open("plain_text_file.txt", "r") as f:
  210. #     # contents = f.read()
  211. #     contents = f.readlines()
  212. # # print(contents)
  213. # for line in contents:
  214. #     line = line.strip()
  215. #     print(line)
  216. # print(contents)
  217.  
  218. import csv
  219. # csv.reader()
  220.  
  221. with open("mock_data.csv", "r") as f1: # mockaroo.com
  222.     # contents = f1.readlines()
  223.     # for row in csv.reader(f1): # csv.reader(f1, delimiter="\t") for tsv files
  224.     #     print(row)
  225.     contents = list(csv.reader(f1))
  226. # print(contents)
  227. # for row in contents[:10]:
  228. #     print(row)
  229.  
  230. # WRITE MODE
  231. # write out a new file where all the last names begin with "P"
  232. # with open("output_data37.csv", "w") as f2:
  233. #     for row in contents:
  234. #         # # ['1', 'Remington', 'Shilling', 'rshilling0@wsj.com', 'Male', '1.71.141.52']
  235. #         # last name is row[2]
  236. #         # if row[2].startswith("P") or row[2].startswith("p"):
  237. #         # if row[2][0].lower() == "p":
  238. #         if row[2].lower().startswith("p"):
  239. #             f2.write(",".join(row) + "\n")
  240.  
  241.  
  242. # APPEND MODE
  243. # reading it to see...
  244. # with open("append_to_this.txt") as f3:
  245. #     print(f3.readlines())
  246.  
  247. with open("append_to_this.txt", "a") as f3:
  248.     f3.write("\nPippin")
  249.  
  250. with open("append_to_this.txt") as f3:
  251.     print(f3.readlines())
  252.  
  253.  
  254.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement