Advertisement
jspill

webinar-python-exam-review-2023-08-26

Aug 26th, 2023
1,352
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.90 KB | None | 1 0
  1. # Exam Review 2023 Aug 26
  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
  7. # Use Submit Mode and get them to 100%!!! And PAY ATTENTION to the unit tests!
  8.  
  9. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  10. # Comp 2: Control Flow
  11. # Comp 3: Modules and Files
  12.  
  13.  
  14. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  15.  
  16. # Operators
  17. # = # assigns
  18. # == # asking if they're equal... a conditional expression
  19. # +
  20. # -
  21. # *
  22. # /
  23. # % # modulo (remainder... whole number)... how many whole things didn't fit since that last even division?
  24. # // # floor division... the last even division
  25. # <
  26. # >
  27. # <=
  28. # >=
  29. # += # x += 1 --> x = x+1
  30. # -= # x -= 1
  31. # ** # raise to a power... math.pow()... or built-in pow()
  32. # !=
  33. # # keywords
  34. # in # if x in myList
  35. # not # if not x in myList
  36. # and
  37. # or # any one True makes the combo True... limit OR to 2-3 conditions
  38.  
  39. # Common Data Types/Classes
  40. # int
  41. # float
  42. # bool # True, False... x < 5... evaluates to True or False... x = 2 print(x > 10) False
  43. # str # "" most important type?
  44. # list # [ ]
  45. # dict # {key: value}
  46. # tuple # ( ) immutable, Python sees x,y,z as (x,y,z) --> return x,y --> return (x,y)
  47. # set # { } all unique/no duplicates, unordered --> no indices, no slicing, no sorting
  48. # range # range()... range(0, 4) --> [0, 1, 2, 3]
  49.  
  50. # Comp 2
  51. # Control Flow! The HOW stuff
  52. # IF statements... if, if/else, if/elif/else, etc
  53. # LOOPS
  54. # WHILE - an IF that repeats
  55. # FOR -  looping over a container, or a known number of times... hence range()
  56. # Check out my For Loops webinar in The Gotchas
  57. # for ___ in _someContainer_:
  58. # for item in myList:
  59. # for char in myStr:
  60. # for key in myDict: # getting the key's value... myDict[key]
  61. # for num in range(0, 8):
  62. # for i in range(len(myList)): # myList[i]
  63. # for i, item in enumerate(myList):
  64.  
  65. # FUNCTIONS
  66. # defining/writing vs calling
  67. # a function has ONE particular job
  68.  
  69. # def someFunction(x, y):
  70. #     return x ** y
  71. #
  72. # if __name__ == "__main__": # is this the script that was run?
  73. #     # here we're solving this particular question (the whole question)
  74. #     myInput = int(input())
  75. #     myOther = int(input())
  76. #     # myNum = someFunction(myInput, myOther)
  77. #     # print(myNum)
  78. #     print(someFunction(myInput, myOther))
  79.  
  80. # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
  81. # # CodingBat also has good function-based Python questions:
  82. # https://codingbat.com/python
  83.  
  84. # BUILT-IN FUNCTIONS
  85. # input()
  86. # print()
  87. # len()
  88. # min()
  89. # max()
  90. # sum()
  91. # list()
  92. # int()
  93. # str()
  94. # dict()
  95. # tuple()
  96. # set()
  97. # float()
  98. # range()
  99. # type() # type("hello").__name__ # str
  100. # enumerate()
  101. # open()
  102. # round()
  103. # help()
  104. # dir()
  105.  
  106. # help(str) # help(str.isspace)
  107. # print(dir(str))
  108.  
  109. # STRINGS
  110. # be able to refer to indices, and slice
  111. # myStr = "abc"
  112. # revStr = myStr[::-1] # mySlice[start:stop:step]
  113. # print(revStr)
  114.  
  115. # KNOW YOUR WHITESPACE
  116. # " " # space from spacebar
  117. # # a lot of Unicode spaces
  118. # "\n" # new line return... print()
  119. # "\t"
  120. # "\r"
  121.  
  122. # STRING METHODS
  123. # myStr.format() # "stuff I want to put together {}".format(var)
  124. # myStr.strip() # input().strip()
  125. # myStr.split() # returns a list of smaller strings
  126. # " ".join(listOfString)
  127. # myStr.replace(subStr, newSubStr) # "remove" myStr = myStr.replace(subStr, "")
  128. # myStr.find(subStr) # return index where found... int
  129. # myStr.count(subStr) # return int count of occurrences
  130. # case: myStr.lower(), myStr.upper(), myStr.title(), myStr.capitalize)()
  131. # is/Boolean: myStr.islower(), .isupper(), .isspace(), .isalpha(), .isalum(), .isnumeric(), .isdigit()
  132. # myStr.startswith(subStr), myStr.endswith(subStr)
  133.  
  134. # LISTS
  135. # be able to ref by index, slice
  136.  
  137. # LIST METHODS
  138. # +
  139. # myList.append(item)
  140. # myList.insert(i, item)
  141. # myList.extend(anotherList)
  142. # # -
  143. # myList.pop(i) # pop by index
  144. # myList.remove(item) # remove by value
  145. # myList.clear()
  146. # # other
  147. # myList.count(item)
  148. # myList.sort() # does not return a value!
  149. # myList.reverse() # does not return a value!
  150. # myList.copy()
  151. # myList.index(item)
  152. #
  153. # # DICT
  154. # # use the key like an index []... then you don't need DICT methods
  155. # myDict[key] # retrieve the value for that key
  156. # myDict[key] = value # assign a new value to that key
  157.  
  158. # # DICT METHODS
  159. # myDict.keys()
  160. # myDict.values()
  161. # myDict.items() # for key, value in myDict.items()
  162. #
  163. # if var in myDict: # looks at keys
  164. #
  165. #
  166.  
  167. # MODULES
  168. # math and csv
  169.  
  170. # MATH MODULE
  171. # import math # FULL IMPORT
  172. # math.factorial(x)
  173. # math.ceil(x.yz)
  174. # math.floor(x.yz)
  175. # math.pow(x, y)
  176. # math.sqrt(x)
  177. # math.fabs(x) # built-in abs()
  178. # math.pi
  179. # math.e
  180.  
  181. # PARTIAL IMPORT
  182. from math import ceil # ceil(x.yz)
  183. from math import factorial, sqrt # factorial(x), sqrt(y)
  184. from math import * # ceil(x.yz)
  185.  
  186. # ALIAS IMPORT
  187. import math as m # m.floor(y.z)
  188.  
  189.  
  190. # FILES
  191.  
  192. # READ MODE
  193. # with open("test.txt", "r") as f:
  194. #     # f.read() # returns whole file as one string
  195. #     # f.readlines() # return a list of strings, line by line
  196. #     contents = f.readlines()
  197. # print(contents)
  198. # for line in contents:
  199. #     line = line.strip()
  200. #     print(line)
  201.  
  202. # CSV Module
  203. import csv
  204. with open("mock_data.csv", "r") as f1: # mockaroo.com
  205.     contents = list(csv.reader(f1)) # contents = csv.reader(f1, delimiter="\t")
  206. # print(contents)
  207.  
  208. # WRITE MODE
  209. with open("output_data24.csv", "w") as f2:
  210.     for row in contents :
  211.         # only write a line to file if email is at .ru address
  212.         # email is at position 3
  213.         if row[3].endswith(".ru"):
  214.             # I'll write with file write()
  215.             f2.write(",".join(row) + "\n")
  216.  
  217. # APPEND MODE
  218. # with open("append_to_this.txt", "r") as f3:
  219. #     print(f3.readlines()) # ['Frodo\n', 'Sam\n', 'Merry']... no line return on last line this time
  220. with open("append_to_this.txt", "a") as f3:
  221.     f3.write("\nPippin") # since there wasn't a line return after Merry I won't add one after Pippin
  222.  
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement