Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exam Review 2021 Nov 11/20
- # LABS
- # Ch 3-13
- # Ch 14-18 not as important
- # Ch 19-30 just LABS, but important practice!
- # Comp 1 Basic syntax and knowledge: operators, data types, etc
- # DATA TYPES
- # strings / str
- # integers / int
- # float
- # list
- # Boolean
- # dictionary / dict
- # tuples
- # set
- # MODULES
- # math
- # csv # often basic filestream methods read(), readlines(), write() that would do just as well
- # OPERATORS
- # +
- # -
- # *
- # /
- # % # whole number remainder! The number of things that DIDN'T FIT
- # // # floor division
- # How many pounds and ounces is 34 oz?
- print(35//16) # gets the pounds
- print(35%16) # get the leftover ounces
- # = # assignment
- # == # "equality operator" checking or asking equality: if/elif, while
- # !=
- # <
- # >
- # <=
- # >=
- # += # x += 1 is the same as x = x+1
- # -=
- # ** # raise to a power, similar math.pow()
- # KEYWORDS that are used like OPERATORS
- # not
- # in # if someItem in someList, if not someItem in someList
- # and
- # or
- # Comp 2: Control Flow Structures
- # IF statements... if, if/else, if/elif/else
- # LOOPS
- # WHILE - like an IF that repeats as long as the condition stays True
- # FOR - doing a known number of times or doing some once for every ITEM in a CONTAINER
- # for someItem for someContainer:
- # for char in myString:
- # for i in range(5): # for i in range(0, 5):
- # for i in range(len(someList)): # someList[i]
- # FUNCTIONS
- # defining vs calling
- # parameters vs "regular" or "outside" variables
- # def myFunction(x):
- # # never say x = something
- # return x//16
- # return vs print() # do whichever one the questions says
- # understand that methods are functions
- # ADVANCED CONTROL STRUCTURES
- # Ch 10: try/except ... Lab 10.7
- # Ch 13: classes
- # defining a function
- # if __name__ = "__main__":
- # if I'm running this script directly
- # myVar = input()
- # myOutput = myFunction(myVar)
- # print(myOutput)
- # BUILT-IN FUNCTIONS
- # print()
- # help() # help(list)
- # dir()
- # print(dir(list))
- # for item in dir(str):
- # if not item.startswith("__"):
- # print(item)
- # len()
- # sum()
- # max()
- # min()
- # int() # int(input())
- # float() # float(input())
- # ord()
- # chr()
- # type()
- # range()
- # STRINGS
- # Build up larger strings with str.format() or f strings
- # string.format()
- # "{} is a variable".format(myVar)
- # f string
- # f"{myVar} is a variable"
- # SLICING STRINGS (or LISTS)
- # myString[start:stop] # myString[start:stop:step]
- # myString = "Just sit right back and you'll hear a tale."
- # # "Just sit"
- # print(myString[0:8])
- # print(myString[::-1])
- # STRING METHODS
- # myString.split()
- # " ".join(someList)
- # myString.format()
- # myString.replace(oldSubString, newSubString) # also to remove
- # myString.upper()
- # myString.isupper()
- # myString.count()
- myList = input.split()
- # LISTS
- # myList.append(item)
- # myList.extend(anotherList)
- # myList.insert(i, item)
- # myList.count(item)
- # myList.remove(item) # by value
- # myList.pop(i) # by index position
- # myList.sort() # myList(reverse=True), compare to sorted() which DOES return a list
- # myList.reverse() # compare to reversed() which DOES return a list
- # if you're confused on how the input data is structured
- print(input()) # see if you get one thing or many
- # Lab question format: keep asking for input() until you see a -1
- x = input()
- while x != "-1":
- # do stuff x
- x = input()
- # if I new these were ints
- x = int(input())
- while x != -1: # while x >= 0:
- # do stuff with x
- x = int(input())
- # Comp 3 opening files
- # good practice here will be Ch 12 Task 4, 7, 8
- f = open(filename, "r")
- contents = f.read()
- contents = f.readlines() # list of strings line by line
- f.close()
- # or
- with open(filename, "r") as f:
- contents = f.readlines()
- # Question on Lab 24.5 Exact Change
- # there's a video on this one as well...
- def exact_change(user_total):
- # figure out the value of each
- money = user_total
- dollars = money // 100
- money = dollars * 100
- quarters = money // 25
- money = quarters * 25
- # and so on...
- return dollars, quarters, dimes, nickels, pennies # this is a tuple, parens or not
- if __name__ == '__main__':
- input_val = int(input())
- num_dollars, num_quarters, num_dimes, num_nickels, num_pennies = exact_change(input_val)
- # function RETURNS those values in a TUPLE, so you can set the 5 vars at once
- # pretty much like this:
- # x, y, z, a, b = (1, 2, 3, 4, 5) # works with lists and tuples
- if input_val <= 0:
- print("no change")
- if num_dollars > 0:
- print(str(num_dollars), end=" ")
- if num_dollars == 1:
- print("dollar")
- else:
- print("dollars")
- # and so on...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement