Fundamentals 7 min read

Five Beginner Python Projects: Rock‑Paper‑Scissors Game, Password Generator, Dice Simulator, Email Sender, and Alarm Clock

This article presents five beginner-friendly Python projects—including a command-line Rock‑Paper‑Scissors game, a random password generator, a dice‑rolling simulator, an automated email sender, and a simple alarm clock—complete with explanations and full source code to help learners practice core programming concepts.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Five Beginner Python Projects: Rock‑Paper‑Scissors Game, Password Generator, Dice Simulator, Email Sender, and Alarm Clock

Python offers a rich ecosystem of third‑party libraries that make it easy to build small, useful utilities. This article introduces five beginner‑level Python projects that illustrate core programming concepts and provide ready‑to‑run source code.

1. Rock‑Paper‑Scissors Game The goal is to create a command‑line game where the player chooses Rock, Paper, or Scissors and competes against a computer‑selected random choice. The score is tracked and displayed when the player ends the game.

import random
choices = ["Rock", "Paper", "Scissors"]
computer = random.choice(choices)
player = False
cpu_score = 0
player_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"Plaer:{player_score}")
        break
    else:
        print("That's not a valid play. Check your spelling!")
    computer = random.choice(choices)

2. Random Password Generator The script asks the user for a desired password length and then creates a random string containing lowercase letters, uppercase letters, digits, and special characters.

import random
passlen = int(input("enter the length of password"))
s = " abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKL MNOPQRSTUVIXYZ!aN$x*6*( )?"
p = "".join(random.sample(s, passlen))
print(p)

3. Dice Simulator A simple loop that prompts the user to press 1 to roll a six‑sided die or 0 to exit, using random.randint to generate the result.

import random
while int(input('Press 1 to roll the dice or 0 to exit:\n')):
    print(random.randint(1, 6))

4. Automatic Email Sender Demonstrates how to compose and send an email via Gmail’s SMTP server using the email.message.EmailMessage class.

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")

5. Simple Alarm Clock The program asks the user for a target time (HH:MM:SS) and continuously checks the current system time. When the specified hour, minute, second, and AM/PM period match, it prints a wake‑up message and plays an audio file using playsound .

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

The article concludes with a QR code that links to a free Python public course and additional learning resources, encouraging readers to explore more advanced material.

Automationcommand linebeginner-projects
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.