Skip to content

Instantly share code, notes, and snippets.

@IvansNab
IvansNab / dateDetection.py
Last active February 13, 2023 13:26
date detection automate the boring stuff
"""Write a regular expression that can detect dates in the DD/MM/YYYY for-
mat. Assume that the days range from 01 to 31, the months range from 01
to 12, and the years range from 1000 to 2999. Note that if the day or month
is a single digit, it’ll have a leading zero.
The regular expression doesn’t have to detect correct days for each
month or for leap years; it will accept nonexistent dates like 31/02/2020 or
31/04/2021. Then store these strings into variables named month, day, and
year, and write additional code that can detect if it is a valid date. April,
June, September, and November have 30 days, February has 28 days, and
the rest of the months have 31 days. February has 29 days in leap years.
@IvansNab
IvansNab / sandwichMaker.py
Last active November 20, 2023 14:49
sandwich maker automate the boring stuff
'''
Write a program that asks users for their sandwich preferences. The pro-
gram should use PyInputPlus to ensure that they enter valid input, such as:
• Using inputMenu() for a bread type: wheat, white, or sourdough.
• Using inputMenu() for a protein type: chicken, turkey, ham, or tofu.
• Using inputYesNo() to ask if they want cheese.
• If so, using inputMenu() to ask for a cheese type: cheddar, Swiss,
or mozzarella.
• Using inputYesNo() to ask if they want mayo, mustard, lettuce, or tomato.
• Using inputInt() to ask how many sandwiches they want. Make sure this
@IvansNab
IvansNab / Write_Your_Own_Multiplication_Quiz.py
Last active January 29, 2023 00:08
write your own multiplication quiz automate the boring stuff
'''
To see how much PyInputPlus is doing for you, try re-creating the multipli-
cation quiz project on your own without importing it. This program will
prompt the user with 10 multiplication questions, ranging from 0 × 0 to
9 × 9. You’ll need to implement the following features:
• If the user enters the correct answer, the program displays “Correct!”
for 1 second and moves on to the next question.
• The user gets three tries to enter the correct answer before the
program moves on to the next question.
• Eight seconds after first displaying the question, the question is
@IvansNab
IvansNab / mcb.pyw
Last active February 26, 2021 10:43
Extending the Multi-Clipboard automate the boring stuff
'''
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.
@IvansNab
IvansNab / madLibs.py
Last active February 27, 2021 19:16
mad libs automate the boring stuff
'''
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
@IvansNab
IvansNab / regexSearch.py
Created February 28, 2021 14:46
regex search automate the boring stuff
'''
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
@IvansNab
IvansNab / selectiveCopy.py
Created March 2, 2021 11:03
selective copy automate the boring stuff
'''
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:
@IvansNab
IvansNab / deletingUnneededFiles.py
Last active March 3, 2021 11:36
deleting unneeded files automate the boring stuff
'''
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.
@IvansNab
IvansNab / fillingInTheGaps.py
Created March 4, 2021 10:37
filling in the gaps automate the boring stuff
'''
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
@IvansNab
IvansNab / 2048.py
Last active March 10, 2021 14:54
2048 automate the boring stuff
'''
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.
'''