Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exam Review 2023 June 24
- # Do those LABS
- # Ch 2-14... all Labs!
- # Ch 21-32 just ADDITIONAL LABS, but important practice!
- # Prac Tests, Ch 33 and 34
- # Use Submit Mode and get them to 100%!!! And PAY ATTENTION to the unit tests!
- # Comp 1: Basic syntax and knowledge: operators, data types, etc
- # Comp 2: Control Flow
- # Comp 3: Modules and Files
- # Watch your string input and output
- # input...
- # myInput = input().strip()
- # output/echo/print()
- # print() # print(end="\n")
- # print("Something I'm printing.",end=" " ) # if we override end...
- # print()
- #print("This should start on a clean new line!")
- # Comp 1: Basic syntax and knowledge: operators, data types, etc
- # Common Data Types
- # int
- # float
- # bool # True, False... x > 3 conditional expressions evaluate to Boolean True or False
- # str # " "
- # list # [ ]
- # dict # {key:value}
- # tuple # ( ) immutable, Python sees x,y,z as (x,y,z) --> return x, y --> return (x, y)
- # set # { } all unique values/no duplicates, no order --> no indices, no slicing, no sorting, no reversing
- # range object # range()... range(0, 5) --> [0, 1, 2, 3, 4]
- # Operators
- # = # assignment, assigning a value
- # == # equality, asking... in a conditional expression
- # +
- # -
- # *
- # /
- # % # modulo... gives an int remainder, "How many whole things didn't fit... since the last even division?"
- # // # floor division... the last even division
- # <
- # >
- # <=
- # >=
- # += # x += 1 --> x = x+1
- # -= # x -= 1 --> x = x - 1
- # ** # raise to a power... pow() and math.pow()
- # !=
- # # keywords
- # in # if x in myList
- # not # if not x in myList
- # and
- # or # any one True means combined condition is True... limit OR to 2-3 conditions
- # Comp 2
- # Control Flow! The HOW stuff
- # IF statements... if, if/else, if/elif, if/elif/else
- # LOOPS
- # WHILE - an IF that repeats
- # FOR - looping over a container, or a known number of times... hence range()
- # Check out my For Loops webinar in The Gotchas
- # for ___ in __someContainer__:
- # for item in myList:
- # for char in myStr:
- # for key in myDict:
- # for num in range(0, 5):
- # for i in range(0, len(myList)): # myList[i]
- # for i, item in enumerate(myList):
- # FUNCTIONS
- # defining/writing vs calling
- # a function has ONE particular job
- # parameters are special variables... they don't work like "regular" variables
- # parameters vs arguments
- # return vs print()/output... or something else?
- # def someFunction(x, y):
- # return x // y
- #
- #
- # if __name__ == "__main__":
- # # we're solving THIS question
- # myInput = int(input())
- # myOther = int(input())
- # myNum = someFunction(myInput, myOther)
- # print(myNum)
- # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
- # # CodingBat also has good function-based Python questions:
- # https://codingbat.com/python
- # BUILT-IN FUNCTIONS
- # print()
- # input()
- # len()
- # type()
- # str()
- # list()
- # int()
- # float()
- # tuple()
- # set()
- # range()
- # min()
- # max()
- # sum()
- # enumerate()
- # sorted()
- # reversed()
- # round() # cousins math.ceil() and math.floor()
- # abs() # compare to math.fabs()
- # pow() # compare to math.pow()
- # open()
- # help() # help(str), help(str.isspace)
- # dir() # print(dir(str))
- # STRINGS
- # be able to refer to indices, and slice
- # myStr = "abcdef"
- # revStr = myStr[::-1] # [start:stop:step]
- # print(revStr)
- # KNOW YOUR WHITESPACE
- # " "
- # # a lot of spaces in Unicode
- # "\n" # new line return
- # "\t" # tab
- # "\r" # carriage return
- # STRING METHODS
- # myStr.format() # "stuff I want to put together {}".format(var)
- # myStr.strip()
- # myStr.split() # returns a list a smaller strings
- # " ".join(listOfStrings)
- # myStr.replace(subStr, newSubStr) # "remove"... myStr = myStr.replace(subStr, "")
- # myStr.find(subStr) # return int index where found, or -1 if not there
- # myStr.count(subStr) # return int of count that subStr
- # case: .lower(), .upper(), .title(), .capitalize()
- # is/Boolean: .isupper(), .islower(), .isspace(), .isalpha(), .isalnum(), .isnumeric(), .isdigit()
- # myStr.startswith(subStr), myStr.endswith(subStr)
- # LISTS
- # be able to use indices, to slice
- # LIST METHODS
- # +
- # myList.append(item)
- # myList.insert(i, item)
- # myList.extend(anotherList)
- # # -
- # myList.pop(i)
- # myList.remove(item) # pop() by index, remove() by value
- # myList.clear()
- # # other
- # myList.count(item)
- # myList.sort()
- # myList.reverse()
- # myList.copy()
- # myList.index(item)
- #
- # # DICT
- # # use the key like an index []
- # myDict[key] # retrieve value for that key
- # myDict[key] = value # assign value to key
- # myDict.keys()
- # myDict.values()
- # myDict.items() # for key, value in myDict.items()
- # MODULES
- # math and csv
- # MATH MODULE
- # import math # FULL IMPORT
- # math.factorial(x)
- # math.ceil(x.yz)
- # math.floor(x.yz)
- # math.pow(x, y)
- # math.sqrt(x)
- # math.fabs(x) # compare abs()
- # math.pi
- # math.e
- # PARTIAL IMPORT
- # from math import factorial # --> factorial(x)
- # from math import ceil, floor # --> ceil(x.yz), floor(x.yz)
- # from math import * # sqrt(x)
- # ALIAS IMPORT
- # import math as m # --> m.floor(x.yz)
- # FILES
- # READ MODE
- # f = open() # old and busted
- # with open("test.txt", "r") as f:
- # contents = f.read() # returns a str of the entire file
- # f.readline()
- # contents = f.readlines() # returns a list of line by line strings
- # print(contents) # ['Hello.\n', 'This\n', 'is\n', 'just\n', 'a\n', 'string.\n', 'But...\n', 'with\n', 'many\n', 'line\n', 'breaks!']
- # for line in contents:
- # line = line.strip() # handle your new line returns as needed
- # print(line)
- # CSV module
- # csv.reader()
- import csv
- with open("mock_data.csv", "r") as f1: # mock data from mockaroo.com
- contents = list(csv.reader(f1)) # for tsv... csv.reader(f1, delimiter="\t")
- # print(contents)
- # for row in contents[0:30]:
- # print(row)
- # WRITE MODE
- with open("output_data21.csv", "w") as f2:
- for row in contents:
- # only write into this new file if email is at photobucket.com
- # email is position 3
- if row[3].endswith("@photobucket.com"): # if "@photobucket" in row[3], or slice it
- # write() takes a single str argument
- f2.write(",".join(row) + "\n")
- # APPEND MODE
- # with open("append_to_this.txt", "r") as f3:
- # contents = f3.readlines()
- # print(contents)
- with open("append_to_this.txt", "a") as f3:
- f3.write("Pippin\n")
- # CA 6.8.2
- num_rows = int(input())
- num_cols = int(input())
- # Note 1: You will need to declare more variables (well, I would)
- # Note 2: Place end=' ' at the end of your print statement to separate seats by spaces
- ''' Your solution goes here '''
- for row in range(1, num_rows+1):
- 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
- for col in range(num_cols):
- print("{}{}".format(row, colLtr), end=" ")
- # x += 1
- colLtr = chr(ord(colLtr)+1)
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement