WGU C859 Python Test 2023 wit complete solution GRADED A+
f1.read() - ANS>>read a file into a string
f1.write("hello!") - ANS>>writes to a
... [Show More] file
f1.readline() - ANS>>reads next line
f1.close() - ANS>>closes a file (must always close a file!)
f1 = open("/my_path/my_file.text", "r") - ANS>>to open and read a file
f1 = open("/my_path/my_file.text", "w") - ANS>>to open and write a file (all previous material discarded)
f1 = open("/my_path/my_file.text", "a") - ANS>>to open and add to a file
with open("/my_file...etc) as f: - ANS>>opens, allows work, and automatically closes a file
timedelta - ANS>>time library function to calculate time amounts
from datetime import timedelta - ANS>>grabs timedelta from the datetime library
import datetime as dt - ANS>>imports a library as a specified variable
datetime.date.today().month - ANS>>to print current month (aka .day or .year for those)
beautiful soup - ANS>>HTML parsing library
NumPy - ANS>>scientific computing, matrices, array creation library
pandas - ANS>>data manipulation and analysis library
pillow (PIL) - ANS>>work with and manipulate images; python imaging library
pyglet - ANS>>multimedia / gaming creation library
pytz - ANS>>time zone data library
pip install ____________ import _______________ - ANS>>to install and import a library into your code
math.ceil() - ANS>>round down (4.5 = 4, 4.8 = 4, 4.1 = 4, 4.9 = 4)
math.floor() - ANS>>round up (4.6 = 5, 4.7 = 5, 4.1 = 5, 4.2 = 5)
datetime.date.today() - ANS>>get today's date
datetime.date.(1967, 9, 7) print(mybday.strftime("%A")) - ANS>>gets the day of the week
math.factorial() - ANS>>multiplies each number in argument to give answer
math.exp() - ANS>>return e raised to power of (x) (natural log)
math.sqrt() - ANS>>return square root of x
os.link() - ANS>>create a hard link pointing to a source
os.getcwd() - ANS>>returns string of current working directory
os.chroot() - ANS>>change the root directory of current process path
os.remove() - ANS>>remove/delete the file path
os.rmdir() - ANS>>remove/delete a directory
random.randrange(start,stop, step) - any or all arguments - ANS>>return a randomly selected element
random.randint(a,b) - ANS>>return a random integer greater than a, less than b
random.random() - ANS>>return next random floating point; range 0.0 to 1.0
random.choice(seq) - ANS>>seq = list; return a random element from the list
import matplotlib.pyplot - ANS>>generates many kinds of plots quickly; works like MATLAB
PIL.image.open() - ANS>>opens up an image
PIL.image.new() - ANS>>creates new image
PIL.image.show() - ANS>>displays image for debugging
PIL.image.save() - ANS>>saves an image in a given filename
pandas.describe() - ANS>>generates descriptive statistics, stats summary
pandas.series() - ANS>>dataframe; 2 dimensional labeled data structure
slicing (with 9 elements, grabbing the first 3) - ANS>>my_list[:3] upper bound is exclusive
slicing(with 9 elements, grabbing the last 3) - ANS>>my_list[6:] lower bound is inclusive
slicing(with 9 elements, grabbing middle 3) - ANS>>my_list[3:6]
mylist.count() - ANS>>counts how many times that item appears
mylist.remove() - ANS>>removes item in a list; example - (0) removes 1st element
mylist.reverse() - ANS>>reverses the items in a list
mylist.pop() - ANS>>removes last item in list
mylist.pop(3) - ANS>>removes 4th item in list
mylist.index(str or int) - ANS>>finds that specific item in list and returns it's index
myset.pop() - ANS>>removes a random element since set are not in any specific order
tuple syntax - ANS>>dimensions = 50, 40, 20
formating - ANS>>print("The ages are {}, {}, and {}.".format(age1, age2, age3))
syntax to add element to a set - ANS>>myset.add("item")
syntax to add element to the end of a list - ANS>>mylist.append("item")
syntax to add element to a specific spot in a list - ANS>>mylist.insert(index, "item")
syntax to create a dictionary - ANS>>mydictionary = {"Elise": 67, "Carlos":66, "Jacquie":92}
syntax to get a specific value in a dictionary - ANS>>mydictionary.get("Elise) will return 67 or print(mydictionary["Elise"] will print 67 [Show Less]