Fundamentals 7 min read

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

This article presents five beginner-friendly Python projects— a command‑line Rock‑Paper‑Scissors game, a random password generator, a dice‑rolling simulator, an automatic email sender, and an alarm clock—each with clear objectives, implementation tips, and complete source code examples.

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

This tutorial introduces five simple Python projects designed for beginners to practice core programming concepts and standard library usage.

1. Rock‑Paper‑Scissors Game

Goal: Create a command‑line game where the player competes against the computer, earning points for each win until the game ends.

Tip: Accept the player's choice, compare it with a randomly selected computer choice, and update scores accordingly.

import random<br/>choices = ["Rock", "Paper", "Scissors"]<br/>computer = random.choice(choices)<br/>player = False<br/>cpu_score = 0<br/>player_score = 0<br/>while True:<br/>    player = input("Rock, Paper or  Scissors?").capitalize()<br/>    # 判断游戏者和电脑的选择<br/>    if player == computer:<br/>        print("Tie!")<br/>    elif player == "Rock":<br/>        if computer == "Paper":<br/>            print("You lose!", computer, "covers", player)<br/>            cpu_score+=1<br/>        else:<br/>            print("You win!", player, "smashes", computer)<br/>            player_score+=1<br/>    elif player == "Paper":<br/>        if computer == "Scissors":<br/>            print("You lose!", computer, "cut", player)<br/>            cpu_score+=1<br/>        else:<br/>            print("You win!", player, "covers", computer)<br/>            player_score+=1<br/>    elif player == "Scissors":<br/>        if computer == "Rock":<br/>            print("You lose...", computer, "smashes", player)<br/>            cpu_score+=1<br/>        else:<br/>            print("You win!", player, "cut", computer)<br/>            player_score+=1<br/>    elif player=='E':<br/>        print("Final Scores:")<br/>        print(f"CPU:{cpu_score}")<br/>        print(f"Plaer:{player_score}")<br/>        break<br/>    else:<br/>        print("That's not a valid play. Check your spelling!")<br/>    computer = random.choice(choices)

2. Random Password Generator

Goal: Build a program that generates a password of user‑specified length using digits, uppercase, lowercase, and special characters.

Tip: Create a character pool containing all required categories and randomly sample the desired length.

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

3. Dice Simulator

Goal: Simulate rolling a six‑sided die on user request.

Tip: Use the random.randint function to produce a number between 1 and 6.

import random;<br/>while int(input('Press 1 to roll the dice or 0 to exit:\n')):  print( random. randint(1,6))<br/>--------------------------------------------------------------------<br/>Press 1 to roll the dice or 0 to exit<br/>1<br/>4

4. Automatic Email Sender

Goal: Write a Python script that sends an email using the built‑in email and smtplib libraries.

Tip: Populate an EmailMessage object with sender, recipient, subject, and content, then connect to an SMTP server to send it.

import smtplib <br/>from email.message import EmailMessage<br/>email = EmailMessage()  ## Creating a object for EmailMessage<br/>email['from'] = 'xyz name'   ## Person who is sending<br/>email['to'] = 'xyz id'       ## Whom we are sending<br/>email['subject'] = 'xyz subject'  ## Subject of email<br/>email.set_content("Xyz content of email")  ## content of email<br/>with smtlib.SMTP(host='smtp.gmail.com',port=587)as smtp:      <br/>    ## sending request to server <br/>    smtp.ehlo()          ## server object<br/>smtp.starttls()      ## used to send data between server and client<br/>smtp.login("email_id","Password")  ## login id and password of gmail<br/>smtp.send_message(email)   ## Sending email<br/>print("email send")    ## Printing success message

5. Alarm Clock

Goal: Create a script that triggers an alarm at a specified time and plays a sound.

Tip: Use the datetime module to compare the current time with the user‑defined alarm time, and playsound to play an audio file when they match.

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

These examples demonstrate how Python’s standard library and third‑party modules can be combined to build practical, interactive command‑line utilities for learning and experimentation.

pythoncommand linescriptingBeginnerprojects
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.