Advertisement
jspill

webinar-exam-review-2022-12-10

Dec 10th, 2022
1,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.56 KB | None | 0 0
  1. # Exam Review Dec 10 2022
  2. # We're limited to 90 minutes today :(
  3.  
  4. # LABS
  5. # Ch 2-14... all Labs!
  6. # Ch 21-34 just ADDITIONAL LABS, but important practice!
  7. # Use Submit Mode!!!
  8.  
  9. # Watch your string input and output
  10. # 1
  11. # myVar = input().strip()
  12.  
  13. # # 2
  14. # print("some stuff", end=" ") # if you ever override end...
  15. # print() # print(end="\n")
  16.  
  17. # print("Clean new line!")
  18.  
  19. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  20. # Comp 2: Control Flow
  21. # Comp 3: Modules and Files
  22.  
  23. # # Comp 1: Basic syntax and knowledge: operators, data types, etc
  24. # operators
  25. # = # assignment
  26. # == # "equality operator"... asking as a comparison
  27. # +
  28. # -
  29. # *
  30. # /
  31. # % # modulo, int remainder... "how many left over?"
  32. # // #  floor division... x//y -> math.floor(x/y), similar to int(x/y)
  33. # <
  34. # >
  35. # <=
  36. # >=
  37. # += # x+=1 -> x = x+1
  38. # -=
  39. # != # not equal
  40. # ** # raising to a power, similar to math.pow()
  41. # # keywords
  42. # in # if _someValue_ in _someContainer_
  43. # not # if not _someValue_ in _someContainer_
  44. # and
  45. # or # any one True means whole condition is True... limit OR to 2 conditions
  46.  
  47. # Common Data Types
  48. # int
  49. # float
  50. # str # ""
  51. # list # []
  52. # set # {}, all unique values, no order
  53. # tuple # (), immutable... Python sees x,y,z as (x,y,z)... return x,y -> return (x,y)
  54. # dict # {key:value}... myList[i]...
  55.  
  56. # myDict[key] = value
  57. # myDict.update({key:value, key:value})
  58.  
  59. # Comp 2
  60. # # the HOW stuff... control flow structures
  61. # IF statements... if, if/else, if/elif/else, etc
  62. # LOOPS
  63. # WHILE - an IF that repeats
  64. # FOR - looping over a container, or a known number of times... range()
  65. # for _item_ in _someContainer_:
  66. # for item in myList:
  67. # for n in range(0, 5): # [0, 1, 2, 3, 4]
  68. # for i in range(len(myList)): # i is the index, myList[i]
  69.  
  70. # FUNCTIONS
  71. # defining/writing vs calling
  72. # parameters are special "variables"... they don't work like "regular" variables
  73. # parameters vs arguments
  74. # a function has ONE particular job
  75. # return vs print()... writes a file... whatever the question says
  76. # method are functions that belong to a particular type/class
  77.  
  78. # def someFunction(x, y):
  79. #     return x + y
  80. #
  81. # if __name__ == "__main__":
  82. #     myNum = int(input())
  83. #     myOtherNum = int(input())
  84. #     num = someFunction(myNum, myOtherNum)
  85. #     print(num)
  86.  
  87. # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
  88. # CodingBat also has good function-based Python questions:
  89. # https://codingbat.com/python
  90.  
  91. # BUILT-IN FUNCTIONS
  92. # print()
  93. # input()
  94. # range()
  95. # list()
  96. # str()
  97. # int()
  98. # float()
  99. # dict()
  100. # tuple()
  101. # set() # list(set(myList))
  102. # len()
  103. # min()
  104. # max()
  105. # sum()
  106. # type()
  107. # myVar = "hey"
  108. # myType = type(myVar)
  109. # print(type(myVar).__name__)# print(myType.__name__)
  110. # round() # but its cousins math.ceil() and math.floor() are in the math
  111. # open() # IO/file .read(), .readlines(), .write()
  112.  
  113. # reversed() # return reversed list... compare to list.reverse() does not return
  114. # sorted() # return sorted list... compare to list.sort() does not return
  115.  
  116. # help(str)
  117. # print(dir(str))
  118. # help(str.isspace)
  119.  
  120. # STRINGS
  121. # be able to slice like it's 2nd nature: myString[start:stop:step]
  122. myString = "abc"
  123. revString = myString[::-1]
  124. print(revString)
  125.  
  126. # KNOW YOUR WHITESPACE
  127. # " " # ... and a lot of other Unicode spaces
  128. # "\n"
  129. # "\r"
  130. # "\t"
  131. # "\f"
  132.  
  133. # STRING METHODS
  134. # "stuff I want to put together {}".format(var) # or similar f strings
  135. # myString.strip() # input().strip()
  136. # myString.split() # returns a list of smaller strings
  137. # ",".join(listOfStrings)
  138. # myString.replace(oldSubStr, newSubStr) # remove... myString.replace(subStr, "")
  139. # myString.find(subStr) # returns int index, or -1
  140. # myString.count(subStr) # return int count of num occurrences
  141. # case: myString.lower(), myString.upper(), myString.title()
  142. # is/Boolean: isupper(), islower(), isalpha(), isdigit(), isalnum(), isspace()
  143.  
  144. # LIST METHODS
  145. # +
  146. # myList.append(item)
  147. # myList.insert(i, item)
  148. # myList.extend(anotherList)
  149. # # -
  150. # myList.pop() # myList.pop(i)... pop() by INDEX
  151. # myList.remove(item) # remove() by VALUE
  152. # # other mods
  153. # myList.count(item) # returns number
  154. # myList.sort()
  155. # myList.reverse()
  156. # # also rans
  157. # myList.clear()
  158. # myList.copy()
  159. # myList.index(item)
  160.  
  161.  
  162. # And we're out of time today!  
  163. # So we didn't get to cover dictionaries and dict methods, modules and the syntax of import statements, or working with FILES!
  164. # We'll have time to finish the whole review next weekend 12/17/22...
  165.  
  166. # Until then, for my whole Exam Review example code see
  167. # https://pastebin.com/VcxsAicR
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement