Advertisement
jspill

webinar-exam-review-2023-03-25

Mar 25th, 2023
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.18 KB | None | 0 0
  1. # Exam Review 2023 Mar 25
  2.  
  3. # LABS
  4. # Ch 2-14... all Labs!
  5. # Ch 21-34 just ADDITIONAL LABS, but important practice!
  6. # Use Submit Mode!!!
  7.  
  8. # Watch your string input and output
  9. # input...
  10. # myVar = input().strip() # myString.strip()
  11. # output/print
  12. # print() # print(end="\n")
  13. # print("some stuff", end=" ")
  14. # print()
  15. # print("Clean new line!")
  16.  
  17. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  18. # Comp 2: Control Flow
  19. # Comp 3: Modules and Files
  20.  
  21. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  22. # Common Data Types
  23. int
  24. float
  25. bool # True, False
  26. str # " "
  27. list # [ ]
  28. dict # {key:value}
  29. tuple # ( ) immutable... Python sees any a,b,c as (a,b,c)... return a,b -> return (a, b)
  30. set # { } all unique values, unordered... no index, no sorting, no slicing
  31. range # range() --> range object [0, 1, 2, 3, 4]
  32.  
  33. # operators
  34. # = # assignment
  35. # == # equality... asking a question, comparing... part of condition
  36. # +
  37. # -
  38. # *
  39. # /
  40. # % # modulo # gives us the int remainder, "how many whole things didn't fit?"
  41. # // # floor division... the last even division
  42. # <
  43. # >
  44. # <=
  45. # >=
  46. # +=
  47. # -=
  48. # ** # raise to a power... pow() or math.pow()
  49. # !=
  50. # # keywords used like operator
  51. # in # if x in myList
  52. # not # if not x in myList
  53. # and
  54. # or #  any one True means whole condition is True... limit OR to 2 conditions
  55.  
  56. # # question on % and //
  57. # print(25%4) # 1
  58. # print(25//4) # 6
  59. #
  60. # print(39%16) # oz left over
  61. # print(39//16) # lbs
  62.  
  63.  
  64. # Comp 2
  65. # the HOW stuff... control flow structures
  66. # IF statements... if, if/else, if/elif, if/elif/else, vs if + if + if
  67. # LOOPS
  68. # WHILE - an IF that repeats
  69. # FOR - looping over a container, or a known number of times #... hence range()
  70. # for _item_ in myList:
  71. # for char in myString:
  72. # for n in range(0, 5): # sorta like [0, 1, 2, 3, 4]
  73. # for i in range(0, len(myList)): # myList[i]
  74. # for key in myDict: # myDict[key]
  75.  
  76. # FUNCTIONS
  77. # defining/writing vs calling
  78. # a function has ONE, PARTICULAR job
  79. # parameter are special variable... they don't work like regular variables
  80. # parameters vs arguments
  81. # return vs print()... vs write a file... whatever the question says
  82.  
  83. # def someFunction(x, y):
  84. #     return x * y # None
  85. # # print('hey') # don't print stuff in here
  86. #
  87. # if __name__ == "__main__": # are we running from this very script I'm writing?
  88. #     myInput = int(input())
  89. #     myOther = int(input())
  90. #     # num = someFunction(myInput, myOther)
  91. #     # print(num)
  92. #     print(someFunction(myInput, myOther))
  93. #
  94.  
  95. # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
  96. # # CodingBat also has good function-based Python questions:
  97. # # https://codingbat.com/python
  98.  
  99. # BUILT-IN FUNCTIONS
  100. # print()
  101. # input()
  102. # len()
  103. # min()
  104. # max()
  105. # sum()
  106. # abs() # math.fabs()
  107. # pow() # math.pow(), **
  108. # round() # math.ceil(), math.floor()
  109. # sorted()  # returns sorted list.. compare list.sort() does not return anything
  110. # reversed() # returns reversed list... same
  111. # int()
  112. # float()
  113. # list()
  114. # str()
  115. # tuple()
  116. # dict()
  117. # set()
  118. # type() # x = [1, 2, 3], print(type(x).__name__)
  119. # range()
  120. # enumerate()
  121. # open() # open a file and create a file/IO stream object
  122. # help() # help(str), help(str.isspace)
  123. # dir() # print(dir(str))
  124.  
  125. # STRINGS
  126. # be able to slice like it's 2nd nature: myString[start:stop:step]
  127. # myStr = "abcdef"
  128. # revStr = myStr[::-1]
  129. # print(revStr)
  130.  
  131. # KNOW YOUR WHITESPACE
  132. # " " # ... many Unicode spaces
  133. # "\n"
  134. # "\t"
  135. # "\r"
  136.  
  137. # STRING METHODS
  138. # myString.format() # "stuff I want to put together {}".format(var)... or similar f strings
  139. # myString.split() # return a list of smaller strings
  140. # myString.join() # " ".join(listOfStrings)
  141. # myString.strip() # lstrip(), rstrip()
  142. # myString.replace(subStr, newStr) # "remove"... myString = myString.replace(subStr, "")
  143. # myString.find(subStr) # return int index where it starts, or -1 on failure
  144. # myString.count(subStr) # return int count
  145. # case: myStr.lower(), myStr.upper(), myStr.title(), myStr.capitalize()
  146. # is/Boolean: myString.isupper(), .islower(), .isspace(), isalpha(), isnumeric(), isalnum(), isdigit()
  147.  
  148. # LISTS
  149. # again know indices and be able to slice
  150.  
  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. # # other
  160. # myList.sort()
  161. # myList.reverse()
  162. # myList.count(item)
  163. # myList.clear()
  164. # myList.copy()
  165. # myList.index(item)
  166.  
  167. # DICT
  168. # use the key like an index
  169. # myDict[key] # retrieve the value for that key, so like get()
  170. # myDict[key] = value # assign a value to the key, so takes the place of update()
  171. # myDict.keys()
  172. # myDict.values()
  173. # pets = {
  174. #     " Agent Scully": "Queequeg",
  175. #     "Fred": "Dino ",
  176. #     "Thor": "Frog Thor"
  177. # }
  178. # pets[key.strip()] = value.strip()
  179.  
  180. # MODULES
  181. # math and csv
  182.  
  183. # MATH MODULE
  184. import math # that's a FULL IMPORT
  185. # math.factorial(x)
  186. # math.ceil(x.yz)
  187. # math.floor(x.yz)
  188. # math.pow(x, y)
  189. # math.sqrt(x)
  190. # math.fabs() # abs()
  191. # math.e
  192. # math.pi
  193.  
  194. # PARTIAL IMPORT
  195. # from math import factorial
  196. # factorial() # not math.factorial()
  197. # from math import floor, sqrt
  198. # floor(), sqrt() # not math.floor(), not math.sqrt()
  199. # from math import *
  200. # but still... factorial(), floor()
  201.  
  202. # ALIAS IMPORT
  203. # import math as m
  204. # m.floor()
  205.  
  206. # FILES!!!
  207. # READ MODE
  208. # with open("test.txt", "r") as f:
  209. #     contents = f.readlines() # # list of strings, line by line
  210. # print(contents)
  211. # for line in contents:
  212. #     # line = line.strip()
  213. #     print(line, end="")
  214. # print()
  215. # print(contents)
  216.  
  217. # CSV Module
  218. # reader() method
  219. # import csv
  220. # with open("mock_data.csv", "r") as f1:
  221. #     contents = list(csv.reader(f1)) # csv.reader(f1, delimiter="\t")
  222. #
  223. # print(contents[0:20])
  224.  
  225. # WRITE MODE
  226. # with open("output_data15.csv", "w") as f2:
  227. #     for line in contents:
  228. #         if len(line[1]) > 9:
  229. #             # write() method takes one single str argument
  230. #             f2.write(",".join(line)+"\n")
  231. #             # f2.write(f"{','.join(line)}\n")
  232.  
  233.  
  234.  
  235. # APPEND MODE
  236. # with open("append_to_this.txt", "r") as f3:
  237. #     contents = f3.readlines()
  238. # print(contents)
  239. # with open("append_to_this.txt", "a") as f4:
  240. #     f4.write("Pippin\n")
  241.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement