Technology education since 2007Live, project-based learningPost-course support

Sample Projects with Python (Sample Project Codes)

You can make simple but meaningful projects with Python. Here are a few sample projects and their associated codes for beginners: 1. Simple Calculator This project takes two numbers and an operation from the user and calculates the result. def

Sample Projects with Python (Sample Project Codes)
Sample Projects with Python (Sample Project Codes)

You can make simple but meaningful projects with Python.

Here are a few sample projects and their associated codes for beginners:

1. Simple Calculator

This project calculates the result by taking two numbers and an action from the user.

def add(x, y):
    return x + y
def subtract(x, y):
    return x - y
def multiply(x, y):
    return x * y
def bol(x, y):
    return x / y
print("Select Action to Be Performed.")
print("1st Addition")
print("2.Subtraction")
print("3rd Multiplication")
print("Part 4")
selection = input("Make your selection(1/2/3/4): ")
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
if selection == '1':
    print(num1, "+", num2, "=", add(num1, num2))
elif selim == '2':
    print(num1, "-", num2, "=", subtract(num1, num2))
elif selim == '3':
    print(num1, "*", num2, "=", multiply(num1, num2))
elif selim == '4':
    print(num1, "/", num2, "=", bol(num1, num2)) You can improve your design skills and make a difference in the digital world with the
else:
    print("Invalid Input")

2. Number Guessing Game

This project relies on the user guessing a number randomly chosen by the computer.
import random
count_predicts = 0
number = random.randint(1, 10)
print("Guess a number between 1 and 10.")
while guess_count < 3:
    guess = int(input("Enter your guess: "))
    guess_count += 1
    if guess < number:
        print("Give me a higher number.")
    elif guess > number:
        print("Give me a lower number.")
    else:
        break
if guess == number:
    print(f"Congratulations! You found the number in {guess_number} tries.")
else:
    print(f"Sorry. The number was {number}.")

3. Simple Database Application

This example simulates a simple database that stores and queries user information in a dictionary.
users = {}
def add_user(id, name):
    users = name
def query_user(id):
    return users.get(id, "User not found")
# Add users
add_user(1, "Ali")
user_add(2, "Ayşe")
# Query user
print(user_query(1)) # Output: Ali
print(query_user(3)) # Output: User not found

4. Simple Chat Bot

This project is a simple chat bot example that responds to certain commands.
def chat_bot(message):
    if message == "Hello":
        return "Hello! How can I help you?"
    elif message == "How are you?":
        return "I'm a bot, thank you. How are you?"
    else:
        return "Sorry, I didn't understand."
message = input("What do you want to call the bot?")
reply = chat_bot(message)
print(answer)

5. Temperature Transducer

This project converts degrees Celsius to degrees Fahrenheit.
def celsius_to_fahrenheit(celsius):
    return (celsius * 9/5) + 32
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = celsius_to_fahrenheit(celsius)
print(f"{celsius} degrees Celsius equals {fahrenheit} degrees Fahrenheit.")

6. Simple Alarm Clock

This project alerts the user at a specific time. (Note: In this example time and datetime modules are used.)
import time
import datetime
def set_alarm(h, m):
    while True:
        if datetime.datetime.now().hour == h and datetime.datetime.now().minute == m:
            print("Alarm! It's time!")
            break
        time.sleep(60)
time = int(input("Enter time for alarm (in 24-hour format): "))
minute = int(input("Enter minute for alarm: "))
set_alarm(hour, minute)

7. Simple File Encryptor

This project simply encrypts the content in a text file.  
def encrypt(text, key):
    password_text = ""
    for letter in text:
        encrypted_text += chr(order(letter) + key)
    return encrypted_text
text = input("Enter the text to be encrypted: ")
key = int(input("Enter the encryption key (integer): ")) It is defined with the
encrypted_text = encrypt(text, key)
print(f"Ciphertext: {ciphertext}")
WHATSAPP • ONLINEChat with usGet information