Homework 5

 feel free to use book/google/youtube/stackoverflow for the scope of this homework 

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Homework5

Policy​:
● feel free to use book/google/youtube/stackoverflow for the scope of this homework
● please keep the work independent, please do not check with each other

Problem 1: Dictionary Practice
Objective

● basic dictionary operations

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Description

● Finishes ​https://holypython.com/beginner-python-exercises/exercise-8-python-dictionaries/​, except for 8-j and
8-k. For each problem, click “Run” button and verify your answer is correct. Print the webpage to pdf and ​submit
to blackboard as proof of done​. If having difficulty printing to pdf, take screenshots and submit to blackboard as
proof of completing the practices.

Problem 2: Frequent Words in Article
Objective

● “with” statement, self learning
● file handling: open, read, looping
● dictionary

Submission

● Please submit the code named ​”word_counter_yourlastname.py”​ to blackboard.

Description & Requirements

You’ll be given a text file “​hw5_input.txt​” and use it as the input file.

Please generate output almost similar to the “​Sample Output​” below. Note my numbers and words are fake, they are
results from the same code on a different input file.

1. open file and read, write function read_text():
○ When opening the file, ​please use ‘with’ statement​. Please google “python with statement”.
○ Read in the file, but ​DO NOT use f.read() method​. Please use ​for loop over the file object​.
○ this function should return a list of words from the input file.
○ please make sure this list of words doesn’t contain empty string, or newline character “\n”

Exercise 8: Dictionaries

2. Please use a dictionary to store the mapping of “word: count_of_word”.
○ Please ​DO NOT use list.count()​. The purpose of this homework is to practice using dict.

3. Please ignore cases when calculating word frequency: “The” and “the” should be considered as the same
words. Please remove punctuation signs as much as you can.

4. For the ‘top 5 (or 10) frequent words’, how to do sorting?
○ can convert dict to list, to help with sorting.
○ or google “dictionary sorting by values python

Notes

● Please use functions as logically separated blocks. Please do not clutter unrelated logic all in the same function.
● Do not repeat code. If a part of calculation can be abstracted into a function for later reuse, do that. Each

occurance of unnecessary repeat of code block will be deducted 5 points.
● Please clean up debugging prints before submission, unnecessary lines like debugging prints will result in 5

points deduction for each occurance. Please make sure to only leave the lines that’s useful, and make sure the
code is nice and clean and easy to understand. Unclean code may get points deducted.

● Code blocks that won’t execute will be deducted 10+ points.

Example Output

Problem 3: Student Courses

Submission

● Please submit the code named ​”student_courses_yourlastname.py”​ to blackboard.
● Please use Python ‘set’ to do the operation: set union, set difference, …

Description
There are hundreds of students in the first year of University X, Major Y. Two programming courses are offered to
these students, course1 and course2. Given the registration info:

course1: [id1, id2, id3, … (integer student ids) …..]
course2: [id2, id3, id6, … (integer student ids) …..]

1. write a function, to get the total sorted list of student ids, that registered for at least 1 programming course. This
list should not contain any duplicated entry. This function should take 2 lists as input arguments: course1 and
course2, and returns a list sorted by student ids, from the smallest to the largest id.

2. write a function, to get the sorted list of student ids, that registered for only 1 programming course. This list
should not contain any duplicated entry. This function should take 2 lists as input arguments similar to above,
and returns a list sorted by student id, from largest to smallest id.

3. write a function, to get a sorted list of student ids that haven’t registered in either of the 2 courses. return sorted
list of student ids from smallest to largest.

4. write a main function that (feel free to separate some of the functionalities below to its own functions)
a. generate 500 random student ids between 4 and 5 digits. No need to handle duplicates for the entire

problem3.
b. generate a random list called “course1” that consists of 400 of the 500 random student ids generated

above. Note, this list should be “random”, meaning, we can’t just assign the first 300 or last 300 of
student ids to “course1”. (hint, random.choice)

c. Similarly, generate a list called “course2” that consists of 400 of the 500 random student ids, also should
be picked randomly.

d. call the 3 functions written in a) and b) and c) and print nice humanly readable results to screens. In this
print, we only print how many student ids in each function return, no need to print all those student ids.

Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.

Order your essay today and save 30% with the discount code ESSAYHELP