To start this assignment, download this zip file.
Homework 6a — Mutability
1. Better Word Count
Write a program in better_word_count.py
that takes one argument:
- an input file name
and prints out a dictionary showing how many words of each word length were found. The program provides counts for all word lengths from 1 to 20.
We have provided you with an example file in words.txt
:
cat catch snooze seven pearl
concatenate silliness you
fireplace it cornered me
When you run the program, it should create this output:
python solutions/better_word_count.py words.txt
{1: 0, 2: 2, 3: 2, 4: 0, 5: 3, 6: 1, 7: 0, 8: 1, 9: 2, 10: 0, 11: 1, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0, 20: 0}
We have also given you some text in 1Nephi.txt
that you can use as a test
file.
Tip
-
Consider using
range()
to create keys for the dictionary and set the initial counts to zero. -
Remember to strip punctuation, specifically
'.,;:!?()'
. This is needed to pass the test cases.
2. Picture Board
Write a program in picture_board.py
that lets you put emojis into a picture
board. The picture board has 5 available positions (identified by the indexes
0-4). The program should:
- display the pictures
- prompt you for a slot and picture
- update the picture board
This repeats until you enter an empty string for the slot.
Follow this input and output carefully:
['', '', '', '', '']
Slot: 0
Pic: ⭐️
['⭐️', '', '', '', '']
Slot: 3
Pic: 🦆
['⭐️', '', '', '🦆', '']
Slot: 2
Pic: 🐟
['⭐️', '', '🐟', '🦆', '']
Slot: 0
Pic: 🚗
['🚗', '', '🐟', '🦆', '']
Slot:
Tip
Consider initializing your board (using a list) before your input loop:
pics = ['', '', '', '', '']
Tests
Be sure you can pass the tests before you turn in the assignment. Review the guide on using pytest if you need to review using pytest and what to do if a test fails.
Grading
Activity | Points |
---|---|
Better word count | 10 |
Picture board | 10 |