100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

D335 Python Endgame Fun-lets Questions and Complete Solutions Graded A+

Rating
-
Sold
-
Pages
4
Grade
A+
Uploaded on
26-03-2025
Written in
2024/2025

D335 Python Endgame Fun-lets Questions and Complete Solutions Graded A+ Convert pairs of values in a csv row into a dictionary - Answer: for row in csv_reader: row_dict = dict(zip(row[::2], row[1::2])) print(row_dict) Extract words listed alphabetically by line from a text file and create a dictionary with the first letter of the words comprising the key, and the words themselves in a list as the corresponding value. - Answer: with open(<file>, 'r') as f: dic = {} lines = ines() for line in lines: dic[line[0]] = () Given a ten-digit integer, isolate the first three, next three and last four digits using floor and modulo. - Answer: #shear right 7 digits first_three = ten_digits // #shear right 4 digits then shear left 3 digits next_three = (ten_digits // 10000) % 1000 #shear left 7 digits last_four = ten_digits % 10000 Insert SSN-style dashes - Answer: original_string = '' formatted_string = original_string[:3] + '-' + original_string[3:5] + '-' + original_string[5:] print(formatted_string) Load the contents of a csv file into memory - Answer: import csv with open('', 'r') as f: csv_reader = r(f) Manipulate text from type() method - Answer: my_string = '' type(my_string).__name__ type_object = type(my_string) type_string = str(type_object) type_name = type_("'")[1] Nest try-except blocks to print errors in a script that divides two integers such that the input of a zero as the divisor or a decimal number prints an error, the latter of which includes the error returned by the interpreter. - Answer: try: inp1 = int(input()) inp2 = int(input()) try: print(int(inp1 / inp2)) except ZeroDivisionError: print(<0 error message>) except ValueError as v: print(<float error message>, v) Open my_ and create a list of lines with n removed - Answer: with open('my_') as f: lines = [() for line in ines()] Print a Fibonacci number from the Fibonacci sequence up to the input integer. Assume all inputs > 0 - Answer: a, b = 0, 1 for r in range(2, int(input())): a, b = b, a + b print(a + b) Raise exceptions for searching a dictionary and output the exception message. Assume the dictionary and a class to create the exception message object are already provided. - Answer: if k in dic: return dic[k] else: raise EntryNotFoundError(f'Value not found for {k}') for k, v in (): if v == value: return k else: raise EntryNotFoundError(f'Key not found for {v}') try: except EntryNotFoundError as excpt: print('<optional message>: ', ge) Replace section of text in my_ - Answer: file_name = 'my_' with open(file_name, 'r+') as f: content = () content = ce('_','_') (0) (content) ate() Sort/clean dictionary - Answer: sorted_dic = {key: dic[key] for key in sorted(dic)} cleaned_dict = {(): () for key, value in my_()}

Show more Read less
Institution
Introduction To Programming In Python - C859
Course
Introduction to Programming in Python - C859








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Introduction to Programming in Python - C859
Course
Introduction to Programming in Python - C859

Document information

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

Subjects

Content preview

D335 Python Endgame Fun-lets
Questions and Complete Solutions
Graded A+
Convert pairs of values in a csv row into a dictionary - Answer: for row in csv_reader:

row_dict = dict(zip(row[::2], row[1::2]))

print(row_dict)



Extract words listed alphabetically by line from a text file and create a dictionary with the first letter of
the words comprising the key, and the words themselves in a list as the corresponding value. - Answer:
with open(<file>, 'r') as f:

dic = {}

lines = f.readlines()

for line in lines:

dic[line[0]] = line.split()



Given a ten-digit integer, isolate the first three, next three and last four digits using floor and modulo. -
Answer: #shear right 7 digits

first_three = ten_digits // 10000000



#shear right 4 digits then shear left 3 digits

next_three = (ten_digits // 10000) % 1000



#shear left 7 digits

last_four = ten_digits % 10000



Insert SSN-style dashes - Answer: original_string = '123456789'



formatted_string = original_string[:3] + '-' + original_string[3:5] + '-' + original_string[5:]

Get to know the seller

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 Grand Canyon University
View profile
Follow You need to be logged in order to follow users or courses
Sold
171
Member since
1 year
Number of followers
26
Documents
14332
Last sold
3 days ago
Your Exm Plug

Assignments, Case Studies, Research, Essay writing service, Questions and Answers, Discussions etc. for students who want to see results twice as fast. I have done papers of various topics and complexities. I am punctual and always submit work on-deadline. I write engaging and informative content on all subjects. Send me your research papers, case studies, psychology papers, etc, and I’ll do them to the best of my abilities. Writing is my passion when it comes to academic work. I’ve got a good sense of structure and enjoy finding interesting ways to deliver information in any given paper. I love impressing clients with my work, and I am very punctual about deadlines. Send me your assignment and I’ll take it to the next level. I strive for my content to be of the highest quality. Your wishes come first— send me your requirements and I’ll make a piece of work with fresh ideas, consistent structure, and following the academic formatting rules. For every student you refer to me with an order that is completed and paid transparently, I will do one assignment for you, free of charge!!!!!!!!!!!!

Read more Read less
4.3

67 reviews

5
38
4
16
3
7
2
4
1
2

Recently viewed by you

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

Frequently asked questions