3 Tiny Python Projects Anyone can Try

Table of contents

As a beginner, I have realized that theoretical knowledge alone can’t get me anywhere, unless I learn how to apply it in practice. However, all these big projects seem scary and impossible to tackle at this stage. So instead, I’ve decided to start small. By just using conditionals, loops, strings and lists, I’ve made 3 tiny projects that helped me apply the basics I’ve learned so far. They are as follows:
Password Generator
This projects generates random strong passwords using letters, numbers and symbols. The main goal was to implement lists, strings and loops in a simple way.
Code:
import random
lower='abcdefghijklmnopqrstuvwxyz'
upper='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits='0123456789'
symbols='!@#$%^&* ()-_+=<>?/'
total=lower+upper+digits+symbols
n=int(input('Enter the required length of password: '))
while n<=12:
print('The length is too small')
n= int(input('Enter the length of password again: '))
#to ensure one of each type is present in the password
password=[random.choice(lower),
random.choice(upper),
random.choice(digits),
random.choice(symbols)]
for i in range(0,n-4):
password.append(random.choice(total))
#shuffling to avoid fixed order of the first 4 character types
random.shuffle(password)
print('Strong Password:',''.join(password))
Let’s break down the logic of this code:
At first, I’ve stored all the numbers, symbols, uppercase and lowercase letters in separate variables. Also, all of these combined are stored in a new variable called
total
.Next, the user is asked to enter the required length of the password which should be greater than or equal to 12. If not, user is asked to enter again until the condition is satisfied.
To ensure that the password is strong, one of each type (uppercase, lowercase, numbers, symbols) is randomly selected and stored in a list.
Finally, remaining number of characters are filled randomly from the
total
variable and everything is shuffled to create the final password.
Note: random
module is imported to generate items in a random order.
Output:
Enter the required length of password: 11
The length is too small
Enter the length of password again: 13
Strong Password: 5xkyJJm*30C$7
So in short, the program takes the user input for length, randomly selects the characters and generates a strong password.
Simple Timer (in Seconds)
For this project, I’ve built a command-line timer where you enter time in seconds and the program counts down until the time’s up. This was useful in learning the Python basics and how Python interacts with time using the time
module.
Code:
import time
t=int(input('Enter time in seconds: '))
print('Timer starts now.')
for i in range(t,0,-1):
print(i,'seconds left')
time.sleep(1)
print("Time's up!!")
Let’s break down the logic of this code:
At first, the user is asked to enter the required time in seconds.
Then, the
for
loop starts the countdown from t to 1 seconds.The
time.sleep(1)
pauses the program for 1 second on each iteration, so that the countdown happens in real time.Finally, the ending message "Time's up!!" is displayed to let the user know the timer has finished.
Output:
Enter time in seconds: 8
Timer starts now.
8 seconds left
7 seconds left
6 seconds left
5 seconds left
4 seconds left
3 seconds left
2 seconds left
1 seconds left
Time's up!!
In short, this program takes user input for a countdown time, uses loop to print the remaining time, pauses the program using time.sleep
and alerts the user when the time is up.
CLI To-Do List
My final mini-project is a very simple To-Do List that allows you to add, view and delete a task from the list inside the command line. It was helpful in learning how to use loops and make a program interactive.
Code:
print('''To-Do List choices:
1. Add task
2. Display the list
3. Remove task
4. Exit ''')
task=[]
while (True):
ch=int(input('\nEnter a choice: '))
if ch==1:
t=input('Enter the task: ')
task.append(t) #adds the task at the end of the list
print('Task added successfully')
elif ch==2:
if not task:
print('The list is empty')
else:
print()
print('-'*12)
print('To-do list:')
print('-'*12)
for i,tasks in enumerate(task): #helps to get the index and the value of the item
print(f'{i+1}. {tasks}')
elif ch==3:
if not task:
print('The list is empty')
else:
print('\nYour Tasks:')
for i,tasks in enumerate(task):
print(f'{i+1}. {tasks}')
r=int(input('\nEnter the number of the task you want to remove: '))
if r<=0 and r>len(tasks):
print('Invalid index')
else:
del task[r-1] #deletes the item from the required index
print('Task removed successfully')
elif ch==4:
print('\nThe End')
break
else:
print('\nInvalid choice.')
Let’s break down the logic of this code:
At first, the user is asked to choose an action: add, display, remove or exit.
Then, according to the choice made by the user, the program checks various condition and executes the matching block of code.
This process continues, allowing user to manage their list, until they make an invalid choice or choose to exit the program.
Output:
To-Do List choices:
1. Add task
2. Display the list
3. Remove task
4. Exit
Enter a choice: 1
Enter the task: Bath
Task added successfully
Enter a choice: 1
Enter the task: Read
Task added successfully
Enter a choice: 1
Enter the task: Cook
Task added successfully
Enter a choice: 1
Enter the task: Exercise
Task added successfully
Enter a choice: 2
------------
To-do list:
------------
1. Bath
2. Read
3. Cook
4. Exercise
Enter a choice: 3
Your Tasks:
1. Bath
2. Read
3. Cook
4. Exercise
Enter the number of the task you want to remove: 3
Task removed successfully
Enter a choice: 2
------------
To-do list:
------------
1. Bath
2. Read
3. Exercise
Enter a choice: 4
The End
In short, this program repeatedly asks the to user choose an action: add, display, remove or exit, executes the required block of code until they choose to exit the program or make an invalid choice.
Conclusion
Altogether, these 3 simple mini-projects gave me the confidence to actually build something real and helped me bring my theoretical knowledge of Python basics into practical use.
If you are a beginner like me and feel intimidated by all these big projects, I suggest you to start small and work your way up.
Hope this blog was helpful. See you next time!!
Subscribe to my newsletter
Read articles from Ashuka Acharya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
