Python is a powerful and versatile coding language, with a wide range of applications. It’s easy to learn, and has become a popular language for many types of projects. If you’re looking to get into coding, or just want to try out some interesting projects, then you should definitely take a look at Python.
Here are 35+ Simple & Advance python projects with source code to try out. From creating a website to writing a game, these projects will get your creative juices flowing and teach you how to use Python in a practical way. With a little bit of dedication and effort, you’ll soon be a Python pro!
What is Python?
If you’ve ever heard of Python, then you know it’s one of the most popular and powerful programming languages out there. But what exactly is it? In short, Python is a high-level, object-oriented programming language that allows developers to create powerful applications quickly and easily.
It’s incredibly versatile and can be used for everything from web and mobile development to artificial intelligence and machine learning. Python is also one of the easiest programming languages to learn. It has a very readable syntax and a large library of built-in functions, making it a great choice for beginners.
Plus, it’s open-source and free, so you don’t have to worry about costly software licenses. With all these advantages, it’s no wonder Python has become so popular. Whether you’re a beginner or an experienced programmer, Python is definitely worth a look.
Benefits of Using Python
- Easy to learn and use
- Large standard library
- Compatibility with major platforms and systems
- Open source with a large community
- Supports multiple programming paradigms
- Extensive support libraries
Python Projects for Beginners – Try Now!
Are you looking for a project to try out your coding skills? Python is a great language for beginners, and there are plenty of projects that you can undertake to sharpen your coding chops. You can create a simple calculator to gain a better understanding of the basics of Python, or you can create a complex web scraper to put your skills to the test. So if you want to take your Python skills to the next level, why not try one of these Python projects for beginners? It could be the perfect way to get started on your coding journey!
1. Alarm Clock using Python Code
This code will keep checking the current time every minute, and when the current time is 7:30 AM (or any other time you specify), it will print “Wake up!” and exit.
To set the alarm for a different time, simply change the values of hour
and minute
in the call to alarm_clock()
. For example, to set the alarm for 6:45 PM, you would call alarm_clock(18, 45)
.
import time
def alarm_clock(hour, minute):
while True:
# Get the current time
current_time = time.localtime()
# Check if the current time is equal to the alarm time
if current_time.tm_hour == hour and current_time.tm_min == minute:
print("Wake up!")
break
# Sleep for a minute before checking the time again
time.sleep(60)
# Set the alarm for 7:30 AM
alarm_clock(7, 30)
2. Animal Quiz Game
This code creates a list of animal names and randomly chooses one to be the answer for the quiz. It then creates an obfuscated version of the answer by replacing each character with an underscore. The user has a certain number of tries to guess the correct animal name, and the code checks if the user’s guess is correct. If the user runs out of tries or guesses the correct answer, the game ends.
import random
# List of animal names
animals = ['lion', 'tiger', 'bear', 'wolf', 'panda']
# Randomly choose an animal from the list
answer = random.choice(animals)
# Obfuscate the animal name by replacing characters with underscores
obfuscated_answer = ['_' for _ in answer]
# Number of tries the user has
tries = 5
while tries > 0:
print("Current status: ", "".join(obfuscated_answer))
guess = input("Guess the animal name: ")
if guess == answer:
print("Congratulations! You guessed the correct animal.")
break
else:
print("Sorry, that is incorrect. Try again.")
tries -= 1
if tries == 0:
print("You have run out of tries. The correct answer was:", answer)
3. BMI Calculator
This code defines a function calculate_bmi
that takes in the weight and height of a person and returns their BMI using the BMI formula: weight (kg) / height (m)^2
. It then prompts the user to enter their weight and height, calculates their BMI using the function, and prints their BMI along with the corresponding weight category based on their BMI value.
def calculate_bmi(weight, height):
# BMI formula: weight (kg) / height (m)^2
bmi = weight / (height ** 2)
return bmi
# Prompt user for weight and height
weight = float(input("Enter your weight (in kg): "))
height = float(input("Enter your height (in m): "))
# Calculate BMI
bmi = calculate_bmi(weight, height)
# Print BMI and corresponding weight category
if bmi < 18.5:
print("Your BMI is", bmi, "which is considered underweight.")
elif 18.5 <= bmi < 25:
print("Your BMI is", bmi, "which is considered normal weight.")
elif 25 <= bmi < 30:
print("Your BMI is", bmi, "which is considered overweight.")
else:
print("Your BMI is", bmi, "which is considered obese.")
4. Converting Roman numbers to Decimals in Python
This code defines a function roman_to_decimal
that takes in a Roman numeral string and returns the corresponding decimal value. It does this by using a dictionary to map each Roman numeral to its corresponding decimal value and iterating through the Roman numerals in the input string from left to right. If the next Roman numeral has a larger value, it subtracts the current value from the result. Otherwise, it adds the value to the result.
def roman_to_decimal(roman):
# Dictionary of Roman numerals and their corresponding decimal values
roman_to_decimal_map = {
'I': 1,
'V': 5,
'X': 10,
'L': 50,
'C': 100,
'D': 500,
'M': 1000
}
# Initialize result
result = 0
# Iterate through the Roman numerals in the input string from left to right
for i, c in enumerate(roman):
# Get the decimal value of the current Roman numeral
value = roman_to_decimal_map[c]
# If the next Roman numeral has a larger value, subtract the current value from the result
# For example, in the Roman numeral 'IV', I = 1 and V = 5, so the result should be 5 - 1 = 4
if i + 1 < len(roman) and roman_to_decimal_map[roman[i + 1]] > value:
result -= value
# Otherwise, add the value to the result
else:
result += value
return result
# Test the function with some Roman numerals
print(roman_to_decimal('I')) # should print 1
print(roman_to_decimal('IV')) # should print 4
print(roman_to_decimal('XVII')) # should print 17
print(roman_to_decimal('MMMDCCCCLXXXXVIIII')) # should print 3999
5. Create Acronyms using Python
This code defines a function create_acronym
that takes in a phrase and returns the corresponding acronym. It does this by splitting the phrase into a list of words, initializing the acronym as an empty string, and iterating through the words in the phrase. If a word is at least two characters long, it adds the first character of the word to the acronym. The function returns the acronym in uppercase.
def create_acronym(phrase):
# Split the phrase into a list of words
words = phrase.split()
# Initialize the acronym as an empty string
acronym = ""
# Iterate through the words in the phrase
for word in words:
# If the word is at least two characters long, use the first character for the acronym
if len(word) > 1:
acronym += word[0]
# Return the acronym in uppercase
return acronym.upper()
# Test the function with some phrases
print(create_acronym("United States of America")) # should print "USA"
print(create_acronym("International Business Machines")) # should print "IBM"
print(create_acronym("HyperText Markup Language")) # should print "HTML"
print(create_acronym("Central Processing Unit")) # should print "CPU"
print(create_acronym("As Soon As Possible")) # should print "ASAP"
6. Dice Roll Simulator
This code imports the random
module and defines a function roll_dice
that generates a random number between 1 and 6 (inclusive) using the randint
function from the random
module. The function returns the dice roll. The code then tests the function by printing the result of three dice rolls.
import random
def roll_dice():
# Generate a random number between 1 and 6 (inclusive)
dice_roll = random.randint(1, 6)
return dice_roll
# Test the dice roll function
print(roll_dice()) # should print a random number between 1 and 6
print(roll_dice()) # should print a random number between 1 and 6
print(roll_dice()) # should print a random number between 1 and 6
7. Email Slicer with Python
This code first splits the email address into a list at the @
symbol, then returns the first part of the list (the username) and the second part of the list (the domain). The function can then be tested by calling email_slicer
and passing in an email address as an argument.
def email_slicer(email):
# Split the email address into a list at the @ symbol
email_parts = email.split("@")
# Return the first part (the username) and the second part (the domain)
return email_parts[0], email_parts[1]
# Test the function
print(email_slicer("john@example.com")) # Output: ("john", "example.com")
8. Fahrenheit to Celcius Converter
def fahrenheit_to_celsius(fahrenheit):
celsius = (fahrenheit - 32) * 5 / 9
return celsius
# Test the function with some values
print(fahrenheit_to_celsius(32)) # Output: 0
print(fahrenheit_to_celsius(212)) # Output: 100
This program defines a function called fahrenheit_to_celsius
that takes a temperature in Fahrenheit as input and returns the equivalent temperature in Celsius. The conversion formula is:
Celsius = (Fahrenheit - 32) * 5 / 9
The function is then tested with two input values: 32 and 212, which should produce output values of 0 and 100 respectively.
9. Generate Password with Python
This program uses the random
and string
modules to generate a random password. The string.ascii_letters
constant contains all the lowercase and uppercase letters, string.digits
contains all the digits, and string.punctuation
contains all the special characters. These three constants are concatenated to create a list of all possible characters for the password.
The list of characters is then shuffled using the random.shuffle
function, and the first length
characters are selected to create the password. The password is returned as a string.
To test the function, we generate an 8-character password and print it to the console. You can modify the length
parameter to generate passwords of different lengths.
import random
import string
def generate_password(length):
# Create a list of all possible characters for the password
characters = string.ascii_letters + string.digits + string.punctuation
# Shuffle the list of characters to get a random order
random.shuffle(characters)
# Select the first `length` characters from the shuffled list
password = "".join(characters[:length])
return password
# Test the function
print(generate_password(8)) # Output: a random 8-character password
10. Play Rock, Paper, and Scissors with Python
This program starts by printing the game instructions and asking the player to enter their choice. The player’s choice is then stored in the player_choice
variable.
The computer makes a random choice from the list of possible choices using the random.choice
function. The winner is determined using an if
statement that checks for the different possible combinations of choices. If the player’s choice and the computer’s choice are the same, it’s a tie. If the player’s choice beats the computer’s choice, the player wins. Otherwise, the computer wins.
Finally, the results of the game are printed to the console. You can modify this program to play multiple rounds of the game, or add additional features like a score counter or a play again prompt.
import random
def play_game():
# Print the game instructions
print("Welcome to the game of rock, paper, scissors!")
print("To play, enter your choice: 'rock', 'paper', or 'scissors'")
# Get the player's choice
player_choice = input("Enter your choice: ")
# Create a list of possible computer choices
computer_choices = ['rock', 'paper', 'scissors']
# Have the computer make a choice
computer_choice = random.choice(computer_choices)
# Determine the winner
if player_choice == computer_choice:
print("It's a tie!")
elif (player_choice == 'rock' and computer_choice == 'scissors') or \
(player_choice == 'paper' and computer_choice == 'rock') or \
(player_choice == 'scissors' and computer_choice == 'paper'):
print("You win!")
else:
print("The computer wins!")
# Start the game
play_game()
11. Print Coloured Text
To print coloured text in a Python terminal, you can use the colored
library. Here is a simple example of how to use this library to print some coloured text:
from termcolor import colored
# Print some text in different colors
print(colored("This text is red", "red"))
print(colored("This text is green", "green"))
print(colored("This text is blue", "blue"))
This program imports the colored
function from the termcolor
library and uses it to print some text in different colors. The colored
function takes two arguments: the text to be printed, and the color to be used.
The available colors are: ‘red’, ‘green’, ‘blue’, ‘cyan’, ‘magenta’, ‘yellow’, and ‘white’. You can also use the on_color
argument to specify a background color for the text.
You can install the termcolor
library using pip:
pip install termcolor
Note that this library only works in terminal environments, and will not produce colored output when run in an IDE or a web-based interpreter like Repl.it.
12. QR Code Generator
To generate QR codes in Python, you can use the qrcode
library. Here is a simple example of how to use this library to generate a QR code image:
import qrcode
# Create a QR code image
img = qrcode.make("This is some data to be encoded in the QR code")
# Save the image to a file
img.save("qr_code.png")
This program imports the qrcode
library and uses the make
function to create a QR code image containing the specified data. The make
function returns a QRCode
object, which has a save
method that can be used to save the image to a file. In this case, the image is saved as a PNG file.
You can install the qrcode
library using pip:
pip install qrcode
You can also customize the appearance of the QR code by setting various options on the QRCode
object, such as the error correction level, the image size, and the border size. For more information, you can refer to the documentation for the qrcode
library.
13. Story Generator with Python
This program defines a list of sentence templates, which can be used to construct a random story. The program then chooses a random number of sentences (between 3 and 7) and selects a random subset of the templates to use. The selected sentences are joined together to form the story, which is then printed to the console.
You can modify this program to generate stories with different lengths or themes, or to use more advanced techniques like natural language processing to create more coherent stories.
import random
# Define a list of sentence templates
sentences = [
"The quick brown fox jumps over the lazy dog.",
"A wickedly curved saber glinted in the light.",
"The air was filled with the sound of steel clashing against steel.",
"A beautiful princess with long golden hair waited patiently in the tower.",
"The brave knight rode into the sunset on his trusty steed.",
"The wicked sorcerer cackled with glee as he unleashed his dark magic.",
"The wise old wizard sat quietly in his chambers, pondering the mysteries of the universe.",
"The forest was eerily quiet as the adventurers made their way through the dense underbrush.",
"A dragon roared in the distance, its fiery breath illuminating the night sky.",
"The kingdom rejoiced as the hero returned victorious from his quest."
]
# Choose a random number of sentences for the story
num_sentences = random.randint(3, 7)
# Choose a random selection of sentences and add them to the story
story = random.sample(sentences, num_sentences)
# Print the story
print(" ".join(story))
14. Taking Multiple User Inputs
To take multiple inputs from the user in Python, you can use the input
function multiple times. Here is an example of how to take three inputs from the user and store them in separate variables:
# Take three inputs from the user name = input("Enter your name: ") age = input("Enter your age: ") location = input("Enter your location: ") # Print the inputs print("Your name is", name) print("Your age is", age) print("Your location is", location)
This program prompts the user for their name, age, and location, and stores the inputs in the variables name
, age
, and location
respectively. The inputs are then printed to the console.
Note that the input
function returns a string, so if you want to store the inputs as numbers (e.g. integer or float), you will need to cast them using the appropriate type. For example:
Copy codeage = int(input("Enter your age: "))
This will store the user’s age as an integer rather than a string. You can use the float
function in a similar way to store the input as a floating point number.