Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exam Review 2022 Feb 19
- # LABS
- # Ch 3-13
- # Ch 14-18 not as important, other than some good labs in Ch 15
- # Ch 19-30 just LABS, but important practice!
- # Use Submit Mode!!!
- # Comp 1: Basic syntax and knowledge: operators, data types, etc
- # Comp 2: Control Flow Structures
- # Basic: if statements, loops, functions
- # Adv: try/except and raising errors, classes
- # Comp 3: modules, working with files
- # Comp 1 Basic syntax and knowledge: operators, data types, etc
- # Data Types
- # str
- # int
- # float
- # list
- # dict # {k:v}
- # set # {1,2,3}, all unique values, have NO ORDER
- # tuple # (1,2,3,1) myTuple[0]
- # Operators
- # +
- # -
- # /
- # *
- # //
- # % # the whole number remainder, "how many things didn't fit?"
- # = # making assignment
- # == # equality operator, asking "are these equal?"
- # +=
- # -=
- # ** # raise to power, similar math.pow()
- # <
- # >
- # <=
- # >=
- # !=
- # # keywords used like operators
- # not
- # in # if item in myList, if not item in myList
- # and
- # or
- # Comp 2: Control Flow Structures
- # Basic...
- # if statements... if, if/else, if/elif/else
- # loops...
- # while
- # for
- # for __ in __:
- # for item in myList:
- # for i in range(len(myList)) # myList[i]
- # for i, item in enumerate(myList)
- # for ___ in myDict: myDict[key] --> value
- # if __ in someDict: # looks at keys, not the values
- # FUNCTIONS
- # defining/writing vs calling
- # parameters/arguments vs "regular" variables
- # a good function has ONE JOB
- # understand built-in functions, class methods: input(), len(), str.split(), dict.update()
- # can return values (or not)
- # def myFunction():
- # do stuff
- # if __name__ = "__main__":
- # myVar = input()
- # call myFunction()
- # BUILT IN FUNCTIONS
- # print()
- # input() # returns str... input().rstrip() weed out whitespace: " ",\n,\r,\t,\f
- # len()
- # sum()
- # min()
- # max()
- # sorted()
- # reversed()
- # round() # and its cousins: math.ceil(), math.floor()
- # range() # and enumerate()
- # help()
- # dir() # print(dir(str))
- # type() # isinstance(myString, str)
- # # create/recasting
- # int() # int(input()) --> int(input().rstrip())
- # float()
- # list()
- # str()
- # tuple()
- # dict()
- # STRING
- # SLICES for strings and list
- # myString[start:stop] # myString[start:stop:step]
- # slice to reverse... myRevString = myString[::-1]
- # STRING METHODS
- # myString.format() # or f strings
- # myString.rstrip() # or myString.strip(), myString.lstrip()
- # myString.split() # returns a list... of string
- # " ".join(myListOfStrings)
- # myString.replace(oldSubStr, newSubStr)
- # myString.count() # there is also list .count()
- # myString.splitlines()
- # case methods: myString.upper(), myString.lower()
- # Boolean methods: myString.isupper(), islower(), isdigit()
- # LIST METHODS
- # myList.append(item)
- # myList.insert(index, item)
- # myList.extend(anotherList)
- # myList.pop() # myList.pop(index)... pop by index
- # myList.remove() # remove by value
- # myList.sort() # "modify in place"
- # myList.reverse()
- # myList.count(item)
- # myList.clear()
- # myList.index(item)
- # # DICTIONARY
- # # myDictionary[key] # retrieves the value
- # # myDictionary[key] = value # assign a value for the key
- # # if __ in myDictionary: # it's checking the keys
- # MATH
- import math # as opposed to from math import factorial
- # math.factorial()
- # math.pow() # **
- # math.sqrt()
- # math.ceil()
- # math.floor()
- # math.e
- # math.pi
- # SETs
- # mySet.add()
- # mySet.pop() # a random value
- # mySet.remove()
- # while item in myList:
- # myList.remove(item)
- # # Comp 3: modules, working with files and modules
- # full import
- # import math --> math.pow(), math.e
- # # partial import
- # from math import factorial --> factorial()
- # from math import * --> still just factorial()
- # # aliased import
- # import math as m --> m.pow(), m.factorial()
- # # OPENING FILES
- # # good practice: Ch 12 Task 4, 7, 8
- # The Gotchas: Working with Files: Reading (25 min)
- # The Gotchas: Working with Files: Writing (33 min)
- # with open(filename, "r") as f:
- # # contents = f.read() # whole file as a big string
- # # contents = f.readlines() # returns a list of line by line strings
- # # # write back out
- # with open(filename, "w") as f:
- # f.write("my string")
- # mock_data.csv
- # import csv # I kinda ignore this....
- with open("mock_data.csv", "r") as f:
- # print(f.read())
- # print(f.readlines())
- for line in f.readlines(): # line is holding a string
- #print(line, end="")
- line = line.strip()
- # print(line)# print(line, end="\n")
- lineList = line.split(",")
- print(lineList[2])
- # The Car Wash dictionary question
- services = { 'Air freshener' : 1 , 'Rain repellent': 2, 'Tire shine' : 2, 'Wax' : 3, 'Vacuum' : 5 }
- base_wash = 10
- total = 0
- # trust no input!!!
- service_choice1 = input().rstrip()
- service_choice2 = input().rstrip()
- ''' Type your code here '''
- total += base_wash
- print("ZyCar Wash")
- print("Base car wash -- $10")
- # don't try to add anything unless you know it's actually in that dictionary!
- if service_choice1 in services:
- total += services[service_choice1] # myDict[key]
- print("{} -- ${}".format(service_choice1, services[service_choice1]))
- if service_choice2 in services:
- total += services[service_choice2] # myDict[key]
- print("{} -- ${}".format(service_choice2, services[service_choice2]))
- print("----")
- print("Total price: ${}".format(total))
Add Comment
Please, Sign In to add comment