Advertisement
jspill

webinar-python-exam-review-2023-06-24

Jun 24th, 2023
1,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.94 KB | None | 0 0
  1. # Exam Review 2023 June 24
  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. # Watch your string input and output
  14. # input...
  15. # myInput = input().strip()
  16. # output/echo/print()
  17. # print() # print(end="\n")
  18. # print("Something I'm printing.",end=" " ) # if we override end...
  19. # print()
  20. #print("This should start on a clean new line!")
  21.  
  22. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  23. # Common Data Types
  24. # int
  25. # float
  26. # bool # True, False... x > 3 conditional expressions evaluate to Boolean True or False
  27. # str # " "
  28. # list # [ ]
  29. # dict # {key:value}
  30. # tuple # ( ) immutable, Python sees x,y,z as (x,y,z) --> return x, y --> return (x, y)
  31. # set # { } all unique values/no duplicates, no order --> no indices, no slicing, no sorting, no reversing
  32. # range object # range()... range(0, 5) --> [0, 1, 2, 3, 4]
  33.  
  34. # Operators
  35. # = # assignment, assigning a value
  36. # == # equality, asking... in a conditional expression
  37. # +
  38. # -
  39. # *
  40. # /
  41. # % # modulo... gives an int remainder, "How many whole things didn't fit... since the last even division?"
  42. # // # floor division... the last even division
  43. # <
  44. # >
  45. # <=
  46. # >=
  47. # += # x += 1 --> x = x+1
  48. # -= # x -= 1 --> x = x - 1
  49. # ** # raise to a power... pow() and math.pow()
  50. # !=
  51. # # keywords
  52. # in # if x in myList
  53. # not # if not x in myList
  54. # and
  55. # or # any one True means combined condition is True... limit OR to 2-3 conditions
  56.  
  57. # Comp 2
  58. # Control Flow! The HOW stuff
  59. # IF statements... if, if/else, if/elif, if/elif/else
  60. # LOOPS
  61. # WHILE - an IF that repeats
  62. # FOR - looping over a container, or a known number of times... hence range()
  63. # Check out my For Loops webinar in The Gotchas
  64. # for ___ in __someContainer__:
  65. # for item in myList:
  66. # for char in myStr:
  67. # for key in myDict:
  68. # for num in range(0, 5):
  69. # for i in range(0, len(myList)): # myList[i]
  70. # for i, item in enumerate(myList):
  71.  
  72. # FUNCTIONS
  73. # defining/writing vs calling
  74. # a function has ONE particular job
  75. # parameters are special variables... they don't work like "regular" variables
  76. # parameters vs arguments
  77. # return vs print()/output... or something else?
  78.  
  79. # def someFunction(x, y):
  80. #     return x // y
  81. #
  82. #
  83. # if __name__ == "__main__":
  84. #     # we're solving THIS question
  85. #     myInput = int(input())
  86. #     myOther = int(input())
  87. #     myNum = someFunction(myInput, myOther)
  88. #     print(myNum)
  89.  
  90. # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
  91. # # CodingBat also has good function-based Python questions:
  92. # https://codingbat.com/python
  93.  
  94. # BUILT-IN FUNCTIONS
  95. # print()
  96. # input()
  97. # len()
  98. # type()
  99. # str()
  100. # list()
  101. # int()
  102. # float()
  103. # tuple()
  104. # set()
  105. # range()
  106. # min()
  107. # max()
  108. # sum()
  109. # enumerate()
  110. # sorted()
  111. # reversed()
  112. # round() # cousins math.ceil() and math.floor()
  113. # abs() # compare to math.fabs()
  114. # pow() # compare to math.pow()
  115. # open()
  116. # help() # help(str), help(str.isspace)
  117. # dir() # print(dir(str))
  118.  
  119. # STRINGS
  120. # be able to refer to indices, and slice
  121. # myStr = "abcdef"
  122. # revStr = myStr[::-1] # [start:stop:step]
  123. # print(revStr)
  124.  
  125. # KNOW YOUR WHITESPACE
  126. # " "
  127. # # a lot of spaces in Unicode
  128. # "\n" # new line return
  129. # "\t" # tab
  130. # "\r" # carriage return
  131.  
  132. # STRING METHODS
  133. # myStr.format() # "stuff I want to put together {}".format(var)
  134. # myStr.strip()
  135. # myStr.split() # returns a list a smaller strings
  136. # " ".join(listOfStrings)
  137. # myStr.replace(subStr, newSubStr) # "remove"... myStr = myStr.replace(subStr, "")
  138. # myStr.find(subStr) # return int index where found, or -1 if not there
  139. # myStr.count(subStr) # return int of count that subStr
  140. # case: .lower(), .upper(), .title(), .capitalize()
  141. # is/Boolean: .isupper(), .islower(), .isspace(), .isalpha(), .isalnum(), .isnumeric(), .isdigit()
  142. # myStr.startswith(subStr), myStr.endswith(subStr)
  143.  
  144. # LISTS
  145. # be able to use indices, to slice
  146.  
  147. # LIST METHODS
  148. # +
  149. # myList.append(item)
  150. # myList.insert(i, item)
  151. # myList.extend(anotherList)
  152. # # -
  153. # myList.pop(i)
  154. # myList.remove(item) # pop() by index, remove() by value
  155. # myList.clear()
  156. # # other
  157. # myList.count(item)
  158. # myList.sort()
  159. # myList.reverse()
  160. # myList.copy()
  161. # myList.index(item)
  162. #
  163. # # DICT
  164. # # use the key like an index []
  165. # myDict[key] # retrieve value for that key
  166. # myDict[key] = value # assign value to key
  167. # myDict.keys()
  168. # myDict.values()
  169. # myDict.items() # for key, value in myDict.items()
  170.  
  171. # MODULES
  172. # math and csv
  173.  
  174. # MATH MODULE
  175. # import math # FULL IMPORT
  176. # math.factorial(x)
  177. # math.ceil(x.yz)
  178. # math.floor(x.yz)
  179. # math.pow(x, y)
  180. # math.sqrt(x)
  181. # math.fabs(x) # compare abs()
  182. # math.pi
  183. # math.e
  184.  
  185. # PARTIAL IMPORT
  186. # from math import factorial # --> factorial(x)
  187. # from math import ceil, floor # --> ceil(x.yz), floor(x.yz)
  188. # from math import * # sqrt(x)
  189.  
  190. # ALIAS IMPORT
  191. # import math as m # --> m.floor(x.yz)
  192.  
  193.  
  194. # FILES
  195.  
  196.  
  197. # READ MODE
  198. # f = open() # old and busted
  199. # with open("test.txt", "r") as f:
  200.     # contents = f.read() # returns a str of the entire file
  201.     # f.readline()
  202.     # contents = f.readlines() # returns a list of line by line strings
  203. # print(contents) # ['Hello.\n', 'This\n', 'is\n', 'just\n', 'a\n', 'string.\n', 'But...\n', 'with\n', 'many\n', 'line\n', 'breaks!']
  204. # for line in contents:
  205. #     line = line.strip() # handle your new line returns as needed
  206. #     print(line)
  207.  
  208. # CSV module
  209. # csv.reader()
  210.  
  211. import csv
  212. with open("mock_data.csv", "r") as f1:      # mock data from mockaroo.com
  213.     contents = list(csv.reader(f1)) # for tsv... csv.reader(f1, delimiter="\t")
  214. # print(contents)
  215. # for row in contents[0:30]:
  216. #     print(row)
  217.  
  218.  
  219.  
  220. # WRITE MODE
  221. with open("output_data21.csv", "w") as f2:
  222.     for row in contents:
  223.         # only write into this new file if email is at photobucket.com
  224.         # email is position 3
  225.         if row[3].endswith("@photobucket.com"): # if "@photobucket" in row[3], or slice it
  226.             # write() takes a single str argument
  227.             f2.write(",".join(row) + "\n")
  228.  
  229.  
  230. # APPEND MODE
  231. # with open("append_to_this.txt", "r") as f3:
  232. #     contents = f3.readlines()
  233. # print(contents)
  234. with open("append_to_this.txt", "a") as f3:
  235.     f3.write("Pippin\n")
  236.  
  237.  
  238.  
  239.  
  240.  
  241. # CA 6.8.2
  242. num_rows = int(input())
  243. num_cols = int(input())
  244.  
  245. # Note 1: You will need to declare more variables (well, I would)
  246. # Note 2: Place end=' ' at the end of your print statement to separate seats by spaces
  247.  
  248. ''' Your solution goes here '''
  249. for row in range(1, num_rows+1):
  250.     colLtr = "A" # we don't _need_ to do this, we could base the letter of col below, but it's easier to make this var
  251.     for col in range(num_cols):
  252.         print("{}{}".format(row, colLtr), end=" ")
  253.         # x += 1
  254.         colLtr = chr(ord(colLtr)+1)
  255. print()
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement