• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 5 pages
Exam (elaborations)

C859 Python Test Questions and Complete Solutions Graded A+

Document preview thumbnail
Preview 2 out of 5 pages

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

Content preview

C859 Python Test Questions and
Complete Solutions Graded A+
f1 = open("/my_path/my_file.text", "r") - Answer: to open and read a file



f1 = open("/my_path/my_file.text", "w") - Answer: to open and write a file (all previous material
discarded)



f1 = open("/my_path/my_file.text", "a") - Answer: to open and add to a file



f1.read() - Answer: read a file into a string



f1.write("hello!") - Answer: writes to a file



f1.readline() - Answer: reads next line



f1.close() - Answer: closes a file (must always close a file!)



with open("/my_file...etc) as f: - Answer: opens, allows work, and automatically closes a file



timedelta - Answer: time library function to calculate time amounts



from datetime import timedelta - Answer: grabs timedelta from the datetime library



import datetime as dt - Answer: imports a library as a specified variable



datetime.date.today().month - Answer: to print current month (aka .day or .year for those)



beautiful soup - Answer: HTML parsing library

, NumPy - Answer: scientific computing, matrices, array creation library



pandas - Answer: data manipulation and analysis library



pillow (PIL) - Answer: work with and manipulate images; python imaging library



pyglet - Answer: multimedia / gaming creation library



pytz - Answer: time zone data library



pip install ____________ import _______________ - Answer: to install and import a library into your
code



math.ceil() - Answer: round down (4.5 = 4, 4.8 = 4, 4.1 = 4, 4.9 = 4)



math.floor() - Answer: round up (4.6 = 5, 4.7 = 5, 4.1 = 5, 4.2 = 5)



datetime.date.today() - Answer: get today's date



datetime.date.(1967, 9, 7)

print(mybday.strftime("%A")) - Answer: gets the day of the week



math.factorial() - Answer: multiplies each number in argument to give answer



math.exp() - Answer: return e raised to power of (x) (natural log)



math.sqrt() - Answer: return square root of x

Document information

Uploaded on
March 26, 2025
Number of pages
5
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$14.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
YourExamplug
4.1
(74)
Sold
228
Followers
27
Items
18118
Last sold
1 day ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions