0% found this document useful (0 votes)
7 views

Madison

The document outlines various Python mini projects, including a Password Locker, a bullet point adder, random quiz generator, file renaming based on date formats, and folder backup into a ZIP file. Each project includes detailed steps for implementation, such as handling command line arguments, manipulating strings, and using libraries like os and shutil. The document serves as a guide for beginners to practice Python programming through practical applications.

Uploaded by

Bharath Bharath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Madison

The document outlines various Python mini projects, including a Password Locker, a bullet point adder, random quiz generator, file renaming based on date formats, and folder backup into a ZIP file. Each project includes detailed steps for implementation, such as handling command line arguments, manipulating strings, and using libraries like os and shutil. The document serves as a guide for beginners to practice Python programming through practical applications.

Uploaded by

Bharath Bharath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Department of information science

Python mini projects

SUBMITTED BY
z Hampritha M
Namita agadi

MS. Kotramma mam


 Project: Password Locker
 Project: Adding Bullets to Wiki
Markup
 Project: Generating Random Quiz
Files
 Project: Renaming Files with
American-Style Dates to European-
Style Dates
 Project: Backing Up a Folder into a
ZIP File
The bulletPointAdder.py script will get the text from the clipboard, add a star and space to
thebeginning of each line, and then paste this new text to the clipboard.
Step 1: Copy and Paste from the Clipboard
➢ You want the bulletPointAdder.py program to do the following:
1.Paste text from the clipboard
2.Do something to it
3. Copy the new text to the clipboard
➢ Steps 1 and 3 are pretty straightforward and involve the pyperclip.copy() and pyperclip.paste()
functions. saving the following program as bulletPointAdder.py:
Step 2: Separate the Lines of Text and Add the Star
➢ The call to pyperclip.paste() returns all the text on the clipboard as one big string. If we used the
“List of Lists of Lists” example, the string stored in text.
➢ The \n newline charactersin thisstring cause it to be displayed with multiple lines when it is
printed or pasted from the clipboard.
➢ We could write code that searches for each \n newline character in the string and then addsthe
star just after that. But it would be easier to use the split() method to return a list of strings, one for
each line in the original string, and then add the star to the front of each string in the list.
Step 3: Join the Modified Lines
➢ The lines list now contains modified lines that start with stars.
➢ pyperclip.copy() is expecting a single string value, not a list ofstring values. To make this single
string value, pass lines into the join() method to get a single string joined from the list’s strings
Project:z Password Locker
Step 1: Program Design and Data Structures
➢ We have to run this program with a command line argument that isthe account’s name- -for
instance, email or blog. That account’s password will be copied to the clipboard so that the user can
paste it into a Password field. The user can have long, complicated passwords without having to
memorize them.
We need to start the program with a #! Line and should also write a comment that briefly
describes the program.Since we want to associate each account’s name with its
password,we can store these as strings in a dictionary
Step 2: Handle Command Line Arguments
➢ The command line arguments will be stored in the variable sys.argv.
➢ The first item in the sys.argv list should always be a string containing the program’s filename
('pw.py'), and the second item should be the first command line argument.
Step 3: Copy the Right Password
➢ The account name isstored as a string in the variable account, you need to see whether it
exists in the PASSWORDS dictionary as a key. If so, you want to copy the key’s value to the
clipboard using pyperclip.copy().

This new code looks in the PASSWORDS dictionary for the account name. If the account name is
a key in the dictionary, we get the value corresponding to that key, copy it to the clipboard, and
print a message saying that we copied the value. Otherwise, we print a message saying there’s
no account with that name.
Here are the steps involved in generating random quiz files in a Python
program:

1. Define Quiz Structure: Determine the format of the quiz, including the types of questions (e.g.,
multiple choice, true/false, short answer), the number of questions, and any other relevant details.
2. Create Question Bank: Develop a database or list of potential questions, answers, and other
relevant information (e.g., question type, difficulty level).
3. Choose Random Questions: Write a function to randomly select a specified number of questions
from the question bank.
4. Generate Quiz File: Create a function to generate a quiz file (e.g., text file, JSON file) containing
the randomly selected questions.
5. Add Quiz Metadata: Include metadata in the quiz file, such as the quiz title, instructions, and any
other relevant information.
6. Format Questions: Format the questions in the desired format (e.g., multiple choice options,
true/false labels).
7. Save Quiz File: Save the generated quiz file to a specified location.
8. Optionally: Add Answer Key: Generate an answer key file containing the correct answers for the
quiz questions.
9. Test and Refine: Test the program with different inputs and refine it as needed to ensure it
generates valid and varied quizzes.
Some Python libraries that can be useful for this task include:
- random for selecting random questions
- json for generating JSON quiz files- csv for generating CSV quiz files
- string for formatting questions and answersBy following these steps, you can create a Python
Here are the steps involved in renaming files with American style dates (MM-DD-YYYY)and
European date style(DD-MM-YYYY) using a Python program:

American Style Dates (MM-DD-YYYY)


1. Import necessary libraries: os for file operations and datetime for date manipulation.
2. Define the date format: date_format = '%m-%d-%Y’
3. Get a list of files: files = os.listdir()
4. Loop through each file: - Get the file name: file_name = file.split('.')[0] - Extract the date:
date = datetime.strptime(file_name, date_format) - Rename the file: os.rename(file,
f"{date.strftime(date_format)}.txt")
European Style Dates (DD-MM-YYYY)
1. Import necessary libraries: os for file operations and datetime for date manipulation.
2. Define the date format: date_format = '%d-%m-%Y’
3. Get a list of files: files = os.listdir()
4. Loop through each file:
-Get the file name:
file_name = file.split('.')[0]
- Extract the date:
date = datetime.strptime(file_name, date_format)
- Rename the file:
os.rename(file, f"{date.strftime(date_format)}.txt")
Common steps
1. Handle exceptions: Add try-except blocks to handle errors during file renaming.
2. Test the program: Run the program with a sample set of files to ensure it works correctly.

Here's a sample Python code snippet that demonstrates the process:

import os
import datetime
# Define the date format
date_format = '%m-%d-%Y’
# American style
# date_format = '%d-%m-%Y’
# European style
# Get a list of files
files = os.listdir()
# Loop through each filefor file in files:
# Get the file name
file_name = file.split('.')[0]
# Extract the date
date = datetime.strptime(file_name, date_format)
# Rename the file os.rename(file, f"{date.strftime(date_format)}.txt")
Note: This code assumes that the file names are in the format "MM-DD-YYYY.txt" or "DD-MM-
YYYY.txt". Adjust the date format and file extension accordingly.
Here's a detailed explanation of the steps involved in backing up a folder into a ZIP file:

Step 1: Import the necessary library


-The shutil library is imported, which provides high-level file operations, including archiving and
compression.
Step 2: Specify the source folder
- The path to the folder that needs to be backed up is specified. This folder contains the files and
subfolders that will be included in the ZIP archive.Step
3: Specify the output ZIP file name- The desired name and path for the output ZIP file are
specified. This will be the name of the ZIP file that will be created.*Step 4: Use the
shutil.make_archive function*
- The shutil.make_archive function is called with the following arguments:
- output_file: The name of the output ZIP file (without the .zip extension).
- format: The format of the archive (in this case, 'zip').
- root_dir: The root directory (the source folder) to archive.
- The function creates a ZIP archive of the specified folder and its contents.
Step 5: Verify the ZIP file creation- After the shutil.make_archive function is called, the script checks
if the ZIP file has been created successfully.
- If the ZIP file is created, a success message is printed to the console.
By following these steps, the script creates a ZIP archive of the specified folder and its contents,
providing a backup of the folder.Note: The shutil.make_archive function automatically includes all
files and subfolders within the specified root directory, so you don't need to manually specify each
file or subfolder to include in the archive.

You might also like