jspill

webinar-python-exam-review-2022-02-29

Feb 19th, 2022
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.35 KB | None | 0 0
  1. # Exam Review 2022 Feb 19
  2.  
  3. # LABS
  4. # Ch 3-13
  5. # Ch 14-18 not as important, other than some good labs in Ch 15
  6. # Ch 19-30 just LABS, but important practice!
  7. # Use Submit Mode!!!
  8.  
  9. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  10. # Comp 2: Control Flow Structures
  11. # Basic: if statements, loops, functions
  12. # Adv: try/except and raising errors, classes
  13. # Comp 3: modules, working with files
  14.  
  15. # Comp 1 Basic syntax and knowledge: operators, data types, etc
  16. # Data Types
  17. # str
  18. # int
  19. # float
  20. # list
  21. # dict # {k:v}
  22. # set # {1,2,3}, all unique values, have NO ORDER
  23. # tuple # (1,2,3,1) myTuple[0]
  24.  
  25. # Operators
  26. # +
  27. # -
  28. # /
  29. # *
  30. # //
  31. # % # the whole number remainder, "how many things didn't fit?"
  32. # = # making assignment
  33. # == # equality operator, asking "are these equal?"
  34. # +=
  35. # -=
  36. # ** # raise to power, similar math.pow()
  37. # <
  38. # >
  39. # <=
  40. # >=
  41. # !=
  42. # # keywords used like operators
  43. # not
  44. # in # if item in myList, if not item in myList
  45. # and
  46. # or
  47.  
  48. # Comp 2: Control Flow Structures
  49. # Basic...
  50. # if statements... if, if/else, if/elif/else
  51. # loops...
  52. # while
  53. # for
  54. # for __ in __:
  55. # for item in myList:
  56. # for i in range(len(myList)) # myList[i]
  57. # for i, item in enumerate(myList)
  58. # for ___ in myDict: myDict[key] --> value
  59. # if __ in someDict: # looks at keys, not the values
  60.  
  61. # FUNCTIONS
  62. # defining/writing vs calling
  63. # parameters/arguments vs "regular" variables
  64. # a good function has ONE JOB
  65. # understand built-in functions, class methods: input(), len(), str.split(), dict.update()
  66. # can return values (or not)
  67.  
  68. # def myFunction():
  69.     # do stuff
  70. # if __name__ = "__main__":
  71. #     myVar = input()
  72. #     call myFunction()
  73.  
  74. # BUILT IN FUNCTIONS
  75. # print()
  76. # input() # returns str... input().rstrip() weed out whitespace: " ",\n,\r,\t,\f
  77. # len()
  78. # sum()
  79. # min()
  80. # max()
  81. # sorted()
  82. # reversed()
  83. # round() # and its cousins: math.ceil(), math.floor()
  84. # range() # and enumerate()
  85. # help()
  86. # dir() # print(dir(str))
  87. # type() # isinstance(myString, str)
  88. # # create/recasting
  89. # int() # int(input()) --> int(input().rstrip())
  90. # float()
  91. # list()
  92. # str()
  93. # tuple()
  94. # dict()
  95.  
  96. # STRING
  97. # SLICES for strings and list
  98. # myString[start:stop] # myString[start:stop:step]
  99. # slice to reverse... myRevString = myString[::-1]
  100. # STRING METHODS
  101. # myString.format() # or f strings
  102. # myString.rstrip() # or myString.strip(), myString.lstrip()
  103. # myString.split() # returns a list... of string
  104. # " ".join(myListOfStrings)
  105. # myString.replace(oldSubStr, newSubStr)
  106. # myString.count() # there is also list .count()
  107. # myString.splitlines()
  108. # case methods: myString.upper(), myString.lower()
  109. # Boolean methods: myString.isupper(), islower(), isdigit()
  110.  
  111. # LIST METHODS
  112. # myList.append(item)
  113. # myList.insert(index, item)
  114. # myList.extend(anotherList)
  115. # myList.pop() # myList.pop(index)... pop by index
  116. # myList.remove() # remove by value
  117. # myList.sort() # "modify in place"
  118. # myList.reverse()
  119. # myList.count(item)
  120. # myList.clear()
  121. # myList.index(item)
  122.  
  123. # # DICTIONARY
  124. # # myDictionary[key] # retrieves the value
  125. # # myDictionary[key] = value # assign a value for the key
  126. # # if __ in myDictionary: # it's checking the keys
  127.  
  128. # MATH
  129. import math # as opposed to from math import factorial
  130. # math.factorial()
  131. # math.pow() # **
  132. # math.sqrt()
  133. # math.ceil()
  134. # math.floor()
  135. # math.e
  136. # math.pi
  137.  
  138. # SETs
  139. # mySet.add()
  140. # mySet.pop() # a random value
  141. # mySet.remove()
  142.  
  143. # while item in myList:
  144. #     myList.remove(item)
  145.  
  146. # # Comp 3: modules, working with files and modules
  147. # full import
  148. # import math --> math.pow(), math.e
  149. # # partial import
  150. # from math import factorial --> factorial()
  151. # from math import * --> still just factorial()
  152. # # aliased import
  153. # import math as m --> m.pow(), m.factorial()
  154.  
  155. # # OPENING FILES
  156. # # good practice: Ch 12 Task 4, 7, 8
  157. # The Gotchas: Working with Files: Reading (25 min)
  158. # The Gotchas: Working with Files: Writing (33 min)
  159.  
  160. # with open(filename, "r") as f:
  161. #     # contents = f.read() # whole file as a big string
  162. #     # contents = f.readlines() # returns a list of line by line strings
  163.  
  164. # # # write back out
  165. # with open(filename, "w") as f:
  166. #     f.write("my string")
  167.  
  168. # mock_data.csv
  169. # import csv # I kinda ignore this....
  170. with open("mock_data.csv", "r") as f:
  171.     # print(f.read())
  172.     # print(f.readlines())
  173.     for line in f.readlines():  # line is holding a string
  174.         #print(line, end="")
  175.         line = line.strip()
  176.         # print(line)# print(line, end="\n")
  177.         lineList = line.split(",")
  178.         print(lineList[2])
  179.  
  180. # The Car Wash dictionary question
  181.  
  182. services = { 'Air freshener' : 1 , 'Rain repellent': 2, 'Tire shine' : 2, 'Wax' : 3, 'Vacuum' : 5 }
  183. base_wash = 10
  184. total = 0
  185.  
  186. # trust no input!!!
  187. service_choice1 = input().rstrip()
  188. service_choice2 = input().rstrip()
  189.  
  190. ''' Type your code here '''
  191. total += base_wash
  192. print("ZyCar Wash")
  193. print("Base car wash -- $10")
  194.  
  195. # don't try to add anything unless you know it's actually in that dictionary!
  196. if service_choice1 in services:
  197.     total += services[service_choice1]  # myDict[key]
  198.     print("{} -- ${}".format(service_choice1, services[service_choice1]))
  199. if service_choice2 in services:
  200.     total += services[service_choice2]  # myDict[key]
  201.     print("{} -- ${}".format(service_choice2, services[service_choice2]))
  202. print("----")
  203. print("Total price: ${}".format(total))
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
Add Comment
Please, Sign In to add comment