Section 5: Practical Projects

Last update: March 30th 2025
  • Create an interactive game where players guess a secret number.
  • Develop a secure password generator with a combination of characters.
  • Apply programming concepts such as loops and functions in practical projects.
  • Improve online security with strong, random passwords.
Section 5: Practical Projects

Welcome to the exciting Practical Projects section in Python! In this section, we will put into practice all the knowledge acquired throughout the course to develop two interesting and useful projects.

In the first project, we will create a Number Guessing Game, where you will test your ability to guess a randomly generated secret number. As you make guesses, the program will provide you with hints to help you get closer to the correct number. It will be an interactive experience that will have you having fun while applying concepts such as random generation, loops, and conditionals.

In the second project, you will dive into building a Password Generator. You will learn how to manipulate strings and lists to build secure, random passwords. With this generator, you will be able to generate strong passwords that meet security standards and protect your online accounts and data.

These hands-on projects will give you the opportunity to apply your skills in real-world situations and help you build your confidence as a Python programmer. Get ready to dive into the fun of programming and elevate your knowledge to a more practical and exciting level! Let's start developing practical Python projects together!

Home Page of the Python Course from Scratch

Return to section 4

5.1 Guess the Number Game

Step-by-step development of an interactive game in Python

In this project, we are going to create an interactive game in Python where the player must guess a randomly generated secret number. As the player makes guesses, the program will provide hints to get closer to the correct number until the player guesses it correctly.

  Codeigniter Framework: A Complete Guide

Step 1: Import the random module to generate the secret number.

 
import random 

Step 2: Generate the random secret number within a specified range.

 
numero_secreto = random.randint(1, 100) 

Step 3: Ask the player to guess the number and keep a guess counter.

 
intentos = 0 

while True: 
    intentos += 1 
    intento = int(input("Intenta adivinar el número secreto (entre 1 y 100): ")) 

Step 4: Compare the player's guess to the secret number and provide clues.

 
    if intento == numero_secreto: 
        print(f"¡Felicidades! ¡Adivinaste el número en {intentos} intentos!") 
        break 
    elif intento < numero_secreto: 
        print("El número secreto es mayor. Sigue intentando.") 
    else: 
        print("El número secreto es menor. Sigue intentando.") 

Step 5: Ask the player if he wants to play again.

 
    jugar_nuevo = input("¿Quieres jugar de nuevo? (s/n): ") 
    if jugar_nuevo.lower() != "s": 
        break 

Example with explanation

Suppose the randomly generated secret number is 68.

 
Intenta adivinar el número secreto (entre 1 y 100): 50 
El número secreto es mayor. Sigue intentando. 

Intenta adivinar el número secreto (entre 1 y 100): 75 
El número secreto es menor. Sigue intentando. 

Intenta adivinar el número secreto (entre 1 y 100): 68 
¡Felicidades! ¡Adivinaste el número en 3 intentos! 

¿Quieres jugar de nuevo? (s/n): n 

In this example, the player made three attempts to guess the secret number 68. Each time the player made an attempt, the program provided hints to help the player get closer to the correct number. After the number was guessed, the program asked the player if he or she wanted to play again. If the player answered “n” (no), the game ended; otherwise, a new game was started with a different random secret number.

Programming Fundamentals
Related articles:
Programming Fundamentals: Basic Concepts

5.2 Password Generator

Creating a program to generate random secure passwords

In this project, we will develop a program that will generate random strong passwords. A strong password must contain a combination of letters (upper and lower case), numbers, and special characters, and be of a specific length.

  Algol programming language: 10 key aspects

Step 1: Import the random module to generate random characters.

 
import random 

Step 2: Define a list of characters allowed in the password.

 
caracteres_permitidos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-+=[]{}" 

Step 3: Prompt the user for the desired password length.

 
longitud_contraseña = int(input("Ingrese la longitud deseada de la contraseña: ")) 

Step 4: Generate the random password by selecting characters from the list.

 
contraseña_generada = "".join(random.sample(caracteres_permitidos, longitud_contraseña)) 

Example with explanation

Suppose the user enters a desired password length of 12.

 
Ingrese la longitud deseada de la contraseña: 12 

The program will generate a random 12-character password using letters (upper and lower case), numbers, and special characters. For example, the generated password could be “5tH!3yLz9W@X”. This password is secure because it meets the length criteria and contains a random combination of characters.

With this password generator, you can create strong, hard-to-guess passwords, which will improve the security of your online accounts and data. Always remember to keep your passwords safe and never share them with anyone!

Computer Systems Engineering
Related articles:
What is Computer Systems Engineering?