Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exam Review 2022 Oct 29
- # LABS
- # Ch 2-14... all Labs!
- # Ch 21-33 just ADDITIONAL LABS, but important practice!
- # Use Submit Mode!!!
- # Watch your string input and output
- # # 1
- # myVar = input().strip() # myVar = input().rstrip()
- # # 2
- # print("some stuff", end=" ") # if you ever override end
- # print() # print(end="\n")
- # print("Clean new line!")
- # # Comp 1: Basic syntax and knowledge: operators, data types, etc
- # # Comp 2: Control Flow
- # # Comp 3: Modules and Files
- # # Comp 1: Basic syntax and knowledge: operators, data types, etc
- # operators
- # = # assigns
- # == # "equality operator", comparison... if/elif, while
- # +
- # -
- # *
- # /
- # % # modulo, int remainder... "how many left over?"
- # // # floor division... x//y -> math.floor(x/y)... for positive numbers int(x/y)
- # <
- # >
- # <=
- # >=
- # += # increment... x+=1 --> x = x+1
- # -= # decrement
- # !=
- # ** # raising to a power, similar to math.pow()
- # # keywords
- # in # if _someValue_ in _someContainer_
- # not # if not _someValue_ in _someContainer_
- # and
- # or # any one True means whole condition is True... limit OR to 2 conditions
- # Common Data Types
- # str # ""
- # int
- # float
- # list # []
- # dict # {key: value}
- # set # {} no order, all unique values
- # tuple # () immutable... Python sees any x,y,z as (x,y,z)... return x,y -> return (x,y)
- # Comp 2
- # # the HOW stuff... control flow structures
- # IF statements... if, if/else, if/elif/else...
- # LOOPS
- # WHILE - an IF that repeats
- # FOR - looping over a container, or a known of times... range()
- # for _item_ in _container_:
- # for item in myList:
- # for n in range(0, 5): # [0, 1, 2, 3, 4]
- # for i in range(0, len(myList)): # myList[i]
- # for key in myDictionary: # myDictionary[key] is that key's value
- # FUNCTIONS
- # defining/writing vs calling
- # parameters are special "variables"... they don't work like "regular" variables
- # parameters vs arguments
- # a function has ONE particular job
- # return vs print()... writes a file... whatever the question says
- # method are functions that belong to a particular type/class
- # def someFunction(x, y):
- # return x + y
- #
- # if __name__ == "__main__":
- # myInput = int(input())
- # myOtherInput = int(input())
- # num = someFunction(myInput, myOtherInput)
- # print(num)
- # # print(someFunction(myInput, myOtherInput))
- # 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()
- # type() # print(type("5").__name__)
- # range()
- # len()
- # sum()
- # min()
- # max()
- # round() # but its cousins math.ceil() and math.floor() are in the math
- # open() # IO/file .read(), .readlines(), .write()
- #
- # reversed() # return reversed list... compare to list.reverse() does not return
- # sorted() # return sorted list... compare to list.sort() does not return
- #
- # # constructor functions
- # str()
- # list()
- # int()
- # float()
- # dict()
- # set()
- # our favorites?
- # help() # help(str), help(str.isdigit)
- # dir() # print(dir(str))
- # STRINGS
- # be able to slice like it's 2nd nature: myString[start:stop:step]
- # myString = "abc"
- # revString = myString[::-1]
- # print(revString)
- # KNOW YOUR WHITESPACE
- # " " # ... and a lot of other Unicode spaces
- # "\n"
- # "\r"
- # "\t"
- # "\f"
- # STRING METHODS
- # "stuff I want to put together {}".format(var) # or similar f strings
- # myString.strip() # input().strip()
- # myString.split() # returns a list of smaller strings
- # ",".join(listOfStrings)
- # myString.replace(oldSubStr, newSubStr) # remove... myString.replace(subStr, "")
- # myString.find(subStr) # returns int index, or -1
- # myString.count(subStr) # return int count of num occurrences
- # case: myString.lower(), myString.upper(), myString.title()
- # is/Boolean: isupper(), islower(), isalpha(), isdigit(), isalnum(), isspace()
- # LISTS
- # again be to slice
- # LIST METHODS
- # +
- # myList.append(item)
- # myList.insert(i, item)
- # myList.extend(anotherList)
- # # -
- # myList.pop() # myList.pop(i)... pop() by INDEX
- # myList.remove(item) # remove() by VALUE
- # # other mods
- # myList.count(item) # returns number
- # myList.sort()
- # myList.reverse()
- # # also rans
- # myList.clear()
- # myList.copy()
- # myList.index(item)
- # DICT
- # use the key like an index
- # # myDict[key] # retrieve the value for that key, so like get()
- # # myDict[key] = value # assign (new) value for that key, so like update({k:v})
- # myDict.keys()
- # myDict.values()
- # myDict.items() # for k, v in myDict.items()... x, y = [2, 8]
- # # MODULES
- # # math and csv
- # # remember there are different import styles that change how you reference them
- # MATH MODULE
- # import math
- # math.factorial(x)
- # math.ceil(x.yz)
- # math.floor(x.zy)
- # math.pow(x, y) # similar to **, not be confused with math.exp()
- # math.sqrt(x)
- # math.fabs() # similar to built-in abs()
- # math.pi
- # math.e
- # PARTIAL IMPORT
- # from math import factorial
- # don't say math.factorial()... we didn't import math
- # factorial() # Drake points appreciately
- # # ALIAS IMPORT
- # # import math as m --> m.floor(), etc
- # FILES!!!
- # with open("test.txt", "r") as f:
- # contents = f.readlines() # a list of line by line str
- # # print(contents)
- # for line in contents:
- # line = line.strip()
- # print(line) # print(line, end="\n")
- # CSV
- # import csv
- # with open("mock_data.csv", "r") as f1:
- # contents = list(csv.reader(f1)) # csv.reader(f1, delimiter="\t")
- # print(contents) # ['7', 'Isidor', 'Hogben', '[email protected]', 'Male', '40.219.108.2']
- #
- # with open("output_data6.csv", "w") as f2:
- # for line in contents:
- # if line[3][-4:] == ".edu":
- # # the write() method takes a SINGLE string as its arg
- # f2.write(",".join(line)+"\n")
- # # f2.write("{}{}".format(",".join(line), "\n")) # or...
- # # f2.write(f"{','.join(line)}{'\n'}")
- # append mode
- with open("append_to_this.txt", "a") as f3:
- f3.write("Pippin\n")
Advertisement
Comments
-
- 27Oct2022_12:48 227b..1977 wooooshhhhh!!!!
- 27Oct2022_12:00 e33f..de19 https://kaildganglife.blogspot.com/2011/03/prison-gangs-one-mexican-mafia-v.html
- 27Oct2022_11:59 4723..b8fc kaildganglife.blogspot.com/2011/04/prison-gangs-two-black-guerilla-family.html
- 27Oct2022_11:56 c17b..026d https://albertsmithirishindependentnewspaper.loforo.com/
- 27Oct2022_11:56 033a..687b https://kiearanconwaysolicitors.loforo.com/
- 27Oct2022_11:55 fe7f..f013 https://wikileaksworldvapour.loforo.com/
- 27Oct2022_10:55 eec6..b073 kiearanconwaysolicitors – Loforo
- 27Oct2022_10:54 5fb7..3573 https://kieranconwaysolicitors.loforo.com/
- 27Oct2022_10:54 a84b..4800 https://wikifreaks-wikifreaks3.loforo.com/
- 27Oct2022_10:53 41f1..2279 https://wikifreaks-wikifreaks2.loforo.com/
- 27Oct2022_10:53 3d53..b7f8 https://wikifreaks-wikifreaks1.loforo.com/
- 27Oct2022_10:52 2015..5334 https://wikifreaks-wikifreaks.loforo.com/
- 27Oct2022_10:51 9938..b81c https://wikifreaksworldvision.loforo.com/
- 27Oct2022_10:51 7532..b464 https://wikifreaks2.loforo.com/
- 27Oct2022_10:50 5b2a..d6e5 https://wikifreaks1.loforo.com/
- 27Oct2022_10:50 c123..c4dc https://wikifreaks.loforo.com/
- 27Oct2022_10:46 0120..ac11 http://www.darkpolitricks.com/2022/10/liz-truss-green-screen-zelenskyy-and.html
-
- 23Oct2022_14:41 9c8c..867c http://www.darkpolitricks.com/2020/11/well-done-america-you-voted-for-what.html
- 23Oct2022_14:33 5bbe..b345 www.darkpolitricks.com/2020/04/well-it-seems-google-really-didnt-like.html
- 23Oct2022_14:32 ed42..e2c8 http://www.darkpolitricks.com/2018/07/israel-is-first-terrorist-state-with.html
- 23Oct2022_14:31 b296..0668 http://www.darkpolitricks.com/2021/05/cia-agent-admits-why-usa-cant-have.html
- 23Oct2022_14:07 4f95..d812 http://www.darkpolitricks.com/2020/04/help-me-create-real-altnews-search.html
- 23Oct2022_14:06 36c5..f4bb http://www.darkpolitricks.com/2020/07/covid19-were-loving-it.html
- 23Oct2022_13:45 2b4e..5780 www.darkpolitricks.com/2022/04/who-are-we-standing-with-when-we-stand.html
- 23Oct2022_13:44 8483..08e3 http://www.darkpolitricks.com/2022/03/the-stupidity-of-russian-sanctions.html
- 23Oct2022_13:42 16a2..10a5 www.darkpolitricks.com/2022/01/how-many-conspiracies-have-to-turn-true.html
- 23Oct2022_13:41 a486..74ba darkpolitricks.com/2021/09/the-uk-is-becoming-more-despotic-every.html
- 23Oct2022_13:40 4605..9f8e http://www.darkpolitricks.com/2021/12/the-internet-is-dead-can-you-prove-it.html
- 23Oct2022_13:35 e899..f184 http://www.darkpolitricks.com/2022/03/two-things-can-be-right-at-same-time.html
- 23Oct2022_13:28 d629..79a9 http://www.darkpolitricks.com/2021/03/is-biden-worse-than-trump.html
- 23Oct2022_13:27 8885..6d01 http://www.darkpolitricks.com/2022/05/here-comes-world-war-iii.html
- 23Oct2022_13:26 6692..546b http://www.darkpolitricks.com/2020/02/am-i-going-down-google-plug-of.html
- 23Oct2022_13:02 c9ef..99d3 wooooshhhhh!!!!
- 23Oct2022_13:01 32e5..289f https://0000001.onepage.website/
- 23Oct2022_12:40 7fea..56ca wooooshhhhh!!!!
- 23Oct2022_12:39 27ba..e21f DICE https://images4.imagebam.com/26/a0/30/MEDWGTV_o.jpeg
- 23Oct2022_12:39 8db8..1808 DICE https://images4.imagebam.com/fb/ef/3f/MEDWGTZ_o.jpeg
- 23Oct2022_12:38 acfb..a06d DICE https://images4.imagebam.com/ea/ea/7d/MEDWGU3_o.jpeg
- 23Oct2022_12:36 fa9d..9191 DICE https://images4.imagebam.com/ef/59/32/MEDWGUA_o.jpeg
- 23Oct2022_12:31 f86d..4195 You having fun?
- 23Oct2022_12:20 3ea8..708c wooooshhhhh!!!!
-
Comment was deleted
Add Comment
Please, Sign In to add comment