Advertisement
jspill

webinar-exam-review-v4-2021-11-20

Nov 20th, 2021
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.72 KB | None | 0 0
  1. # Exam Review 2021 Nov 11/20
  2.  
  3. # LABS
  4. # Ch 3-13
  5. # Ch 14-18 not as important
  6. # Ch 19-30 just LABS, but important practice!
  7.  
  8. # Comp 1 Basic syntax and knowledge: operators, data types, etc
  9. # DATA TYPES
  10. # strings / str
  11. # integers / int
  12. # float
  13. # list
  14. # Boolean
  15. # dictionary / dict
  16. # tuples
  17. # set
  18. # MODULES
  19. # math
  20. # csv # often basic filestream methods read(), readlines(), write() that would do just as well
  21.  
  22. # OPERATORS
  23. # +
  24. # -
  25. # *
  26. # /
  27. # % # whole number remainder! The number of things that DIDN'T FIT
  28. # // # floor division
  29. # How many pounds and ounces is 34 oz?
  30. print(35//16) # gets the pounds
  31. print(35%16) # get the leftover ounces
  32. # = # assignment
  33. # == # "equality operator" checking or asking equality: if/elif, while
  34. # !=
  35. # <
  36. # >
  37. # <=
  38. # >=
  39. # += # x += 1 is the same as x = x+1
  40. # -=
  41. # ** # raise to a power, similar math.pow()
  42. # KEYWORDS that are used like OPERATORS
  43. # not
  44. # in # if someItem in someList, if not someItem in someList
  45. # and
  46. # or
  47.  
  48. # Comp 2: Control Flow Structures
  49. # IF statements... if, if/else, if/elif/else
  50. # LOOPS
  51. # WHILE - like an IF that repeats as long as the condition stays True
  52. # FOR - doing a known number of times or doing some once for every ITEM in a CONTAINER
  53. # for someItem for someContainer:
  54. # for char in myString:
  55. # for i in range(5): # for i in range(0, 5):
  56. # for i in range(len(someList)): # someList[i]
  57. # FUNCTIONS
  58. # defining vs calling
  59. # parameters vs "regular" or "outside" variables
  60. # def myFunction(x):
  61. #     # never say x = something
  62. #     return x//16
  63. # return vs print() # do whichever one the questions says
  64. # understand that methods are functions
  65.  
  66. # ADVANCED CONTROL STRUCTURES
  67. # Ch 10: try/except ... Lab 10.7
  68. # Ch 13: classes
  69.  
  70. # defining a function
  71. # if __name__ = "__main__":
  72.     # if I'm running this script directly
  73.     # myVar = input()
  74.     # myOutput = myFunction(myVar)
  75.     # print(myOutput)
  76.  
  77. # BUILT-IN FUNCTIONS
  78. # print()
  79. # help() # help(list)
  80. # dir()
  81. # print(dir(list))
  82. # for item in dir(str):
  83. #     if not item.startswith("__"):
  84. #         print(item)
  85. # len()
  86. # sum()
  87. # max()
  88. # min()
  89. # int() # int(input())
  90. # float() # float(input())
  91. # ord()
  92. # chr()
  93. # type()
  94. # range()
  95.  
  96. # STRINGS
  97. # Build up larger strings with str.format() or f strings
  98. # string.format()
  99. # "{} is a variable".format(myVar)
  100. # f string
  101. # f"{myVar} is a variable"
  102.  
  103. # SLICING STRINGS (or LISTS)
  104. # myString[start:stop] # myString[start:stop:step]
  105. # myString = "Just sit right back and you'll hear a tale."
  106. # # "Just sit"
  107. # print(myString[0:8])
  108. # print(myString[::-1])
  109.  
  110. # STRING METHODS
  111. # myString.split()
  112. # " ".join(someList)
  113. # myString.format()
  114. # myString.replace(oldSubString, newSubString) # also to remove
  115. # myString.upper()
  116. # myString.isupper()
  117. # myString.count()
  118.  
  119. myList = input.split()
  120.  
  121. # LISTS
  122. # myList.append(item)
  123. # myList.extend(anotherList)
  124. # myList.insert(i, item)
  125. # myList.count(item)
  126. # myList.remove(item) # by value
  127. # myList.pop(i) # by index position
  128. # myList.sort() # myList(reverse=True), compare to sorted() which DOES return a list
  129. # myList.reverse() # compare to reversed() which DOES return a list
  130.  
  131.  
  132. # if you're confused on how the input data is structured
  133. print(input()) # see if you get one thing or many
  134.  
  135. # Lab question format: keep asking for input() until you see a -1
  136. x = input()
  137. while x != "-1":
  138.     # do stuff x
  139.     x = input()
  140.  
  141. # if I new these were ints
  142. x = int(input())
  143. while x != -1: # while x >= 0:
  144.     # do stuff with x
  145.     x = int(input())
  146.  
  147. # Comp 3 opening files
  148. # good practice here will be Ch 12 Task 4, 7, 8
  149. f = open(filename, "r")
  150. contents = f.read()
  151. contents = f.readlines() # list of strings line by line
  152. f.close()
  153. # or
  154. with open(filename, "r") as f:
  155.     contents = f.readlines()
  156.  
  157. # Question on Lab 24.5 Exact Change
  158. # there's a video on this one as well...
  159. def exact_change(user_total):
  160.     # figure out the value of each
  161.     money = user_total
  162.     dollars = money // 100
  163.     money = dollars * 100
  164.  
  165.     quarters = money // 25
  166.     money = quarters * 25
  167.     # and so on...
  168.     return dollars, quarters, dimes, nickels, pennies # this is a tuple, parens or not
  169.  
  170.  
  171. if __name__ == '__main__':
  172.     input_val = int(input())
  173.     num_dollars, num_quarters, num_dimes, num_nickels, num_pennies = exact_change(input_val)
  174.     # function RETURNS those values in a TUPLE, so you can set the 5 vars at once
  175.     # pretty much like this:
  176.     # x, y, z, a, b = (1, 2, 3, 4, 5) # works with lists and tuples
  177.     if input_val <= 0:
  178.         print("no change")
  179.  
  180.     if num_dollars > 0:
  181.         print(str(num_dollars), end=" ")
  182.         if num_dollars == 1:
  183.             print("dollar")
  184.         else:
  185.             print("dollars")
  186.  
  187.         # and so on...
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement