This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Spreadsheet Cell Inverter | |
| Write a program to invert the row and column of the cells in the spread- | |
| sheet. For example, the value at row 5, column 3 will be at row 3, column 5 | |
| (and vice versa). This should be done for all cells in the spreadsheet. | |
| ITEM SOLD | |
| Apples 73 | |
| Cherries 85 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Blank Row Inserter | |
| Create a program blankRowInserter.py that takes two integers and a filename | |
| string as command line arguments. Let’s call the first integer N and the sec- | |
| ond integer M. Starting at row N, the program should insert M blank rows | |
| into the spreadsheet. For example, when the program is run like this: | |
| python blankRowInserter.py 3 2 myProduce.xlsx | |
| A B C | |
| 1 asdf asdf asdf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Multiplication Table Maker | |
| Create a program multiplicationTable.py that takes a number N from the | |
| command line and creates an N×N multiplication table in an Excel spreadsheet. | |
| For example, when the program is run like this: | |
| py multiplicationTable.py 3 | |
| . . . it should create a spreadsheet: | |
| A B C D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| 2048 | |
| 2048 is a simple game where you combine tiles by sliding them up, down, | |
| left, or right with the arrow keys. You can actually get a fairly high score | |
| by repeatedly sliding in an up, right, down, and left pattern over and over | |
| again. Write a program that will open the game at https://gabrielecirulli | |
| .github.io/2048/ and keep sending up, right, down, and left keystrokes to | |
| automatically play the game. | |
| ''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Filling in the Gaps | |
| Write a program that finds all files with a given prefix, such as spam001.txt, | |
| spam002.txt, and so on, in a single folder and locates any gaps in the num- | |
| bering (such as if there is a spam001.txt and spam003.txt but no spam002.txt). | |
| Have the program rename all the later files to close this gap. | |
| As an added challenge, write another program that can insert gaps | |
| into numbered files so that a new file can be added. | |
| ''' | |
| import pyinputplus as pyip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Deleting Unneeded Files | |
| It’s not uncommon for a few unneeded but humongous files or folders to | |
| take up the bulk of the space on your hard drive. If you’re trying to free up | |
| room on your computer, you’ll get the most bang for your buck by deleting | |
| the most massive of the unwanted files. But first you have to find them. | |
| Write a program that walks through a folder tree and searches for excep- | |
| tionally large files or folders—say, ones that have a file size of more than | |
| 100MB. (Remember that to get a file’s size, you can use os.path.getsize() from | |
| the os module.) Print these files with their absolute path to the screen. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Selective Copy | |
| Write a program that walks through a folder tree and searches for files with | |
| a certain file extension (such as .pdf or .jpg). Copy these files from whatever | |
| location they are in to a new folder. | |
| ''' | |
| import shutil, os | |
| def pathInputAndCheck(): | |
| while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Write a program that opens all .txt files in a folder and searches for any | |
| line that matches a user-supplied regular expression. The results should | |
| be printed to the screen. | |
| ''' | |
| import re | |
| from pathlib import Path | |
| import pyinputplus as pyip | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Create a Mad Libs program that reads in text files and lets the user add | |
| their own text anywhere the word ADJECTIVE, NOUN, ADVERB, or VERB | |
| appears in the text file. For example, a text file may look like this: | |
| The ADJECTIVE panda walked to the NOUN and then VERB. A nearby NOUN was | |
| unaffected by these events. | |
| The program would find these occurrences and prompt the user to | |
| replace them. | |
| Enter an adjective: | |
| silly |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Extending the Multi-Clipboard | |
| Extend the multi-clipboard program in this chapter so that it has a delete | |
| <keyword> command line argument that will delete a keyword from the shelf. | |
| Then add a delete command line argument that will delete all keywords. | |
| ''' | |
| #! python3 | |
| # mcb.pyw - Saves and loads pieces of text to the clipboard. | |
| # Usage: py.exe mcb.pyw save <keyword> - Saves clipboard to keyword. | |
| # py.exe mcb.pyw <keyword> - Loads keyword to clipboard. |