Automate the Boring Stuff - Projects !

Kirtipurohit
3 min readSep 28, 2020
Photo by James Pond on Unsplash

Contents:

  1. The password detection program
  2. Generating Random quiz file
  3. Mad Libs
  4. Selective Copy

The Password detection Program

import repassStrong=False
def passStrength():
password=input('Enter your password')
lowerRegex=re.compile(r'[a-z]+')
upperRegex=re.compile(r'[A-Z]+')
digitRegex=re.compile(r'[0-9]+')
charRegex=re.compile(r'(\w{8,})')
if charRegex.findall(password) == []:
print('Password must contain atleast 8 characters')
elif digitRegex.findall(password)==[]:
print('Password must contain atleast one digit')
elif upperRegex.findall(password)==[]:
print('Password must contain atleast one uppercase letter')
elif lowerRegex.findall(password)==[]:
print('Password must contain atleast one letter')
else:
print("The password is strong.Good Job!")
passStrong=True
return
while not passStrong:
passStrength()

Project: Generating Random Quiz Files

Say you’re a geography teacher with 35 students in your class and you want

to give a pop quiz on US state capitals. Alas, your class has a few bad eggs in

it, and you can’t trust the students not to cheat. You’d like to randomize the

order of questions so that each quiz is unique, making it impossible for anyone

to crib answers from anyone else. Of course, doing this by hand would

be a lengthy and boring affair. Fortunately, you know some Python.

Here is what the program does:

• Creates 35 different quizzes.

• Creates 50 multiple-choice questions for each quiz, in random order.

• Provides the correct answer and three random wrong answers for each

question, in random order.

• Writes the quizzes to 35 text files.

• Writes the answer keys to 35 text files.

This means the code will need to do the following:

• Store the states and their capitals in a dictionary.

• Call open(), write(), and close() for the quiz and answer key text files.

• Use random.shuffle() to randomize the order of the questions and multiple-choice options.

NOTE: The code is written for 10 question papers

Here is the output file,

These are all the files generated on the left side .

quizFile=open('Capitalquiz%s.txt' %(quiznum +1) , 'w+')

The w+ command writes into a file and if the file doesn’t exist , it creates a file. Everytime you run the program you will find that the content generated in the file is being updated

Project : Mad Libs

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:

cute

Enter a noun:

lake

Enter a verb:

screamed

Enter a noun:

garden

The following text file would then be created:

The cute panda walked to the lake and then screamed. A nearby garden was unaffected by these events.

Here is the code snip for it.

Basically , mad.txt is the source file where the changes will take place for our input.

After execution the content in the file will look like,

Project — 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

Here is my output which looks like,

That’s it for now ! I will keep on adding more and please let me know if I missed something out or gone wrong !

Thank You !

~kirti

--

--

Kirtipurohit

Programmer | Technical content Writer | Lives in India | Wanna go where I can breathe freedom