4 Beginner Python Projects with Source Code

So there are a lot of python projects one can do as a beginner. You may have heard of beginner python projects like Rolling the dice, Tic Tac Toe, etc in Python, right?

Beginner Python Projects – Prerequisite

We’re going to build some of these python projects now. Before jumping into projects, make sure you have a basic understanding of how Python works and a few basic things like loops and statements.

1. Rolling The Dice Game

So let’s get started with the first one. The rolling dice game in Python.

import random
min = 1
max = 6

roll_again = "yeah"

while roll_again == "yeah":
    print("Rolling the dices...")
    print("The values are....")
    print(random.randint(min, max))
    print(random.randint(min, max))

    roll_again = raw_input("Roll the dices again?")


As the name suggests, this game will print a random number between 2 values. So we know that the minimum value in dice is 1 and the maximum value of that dice is 6.

Therefore, we will assign these values to 2 variables. But wait, how do I get these random numbers? This is where we use random module.

First, you’ll have to import the random module because we want to randomize the numbers.

The user will need to roll the dice again. So, we use the while loop after assigning the variables. Next, we’ll set the value for the variable “roll_again”. We’re going to set this to “Yeah” but it can be anything else.

As a result, we have this Rolling the Dice game successfully running.

Make sure you play around with these beginner python projects so you will understand them better.

2. Guess the Number – Game

Let’s create a game in which the user will have to guess the number between two values. The number can be any number that will be randomly picked.

#import random module
import random

hidden = random.randrange(1, 1001)

guess = int(input("Guess the Number: "))

if guess == hidden:

elif guess < hidden:
	print("Too low")

	print("Too High")


First off, we imported the Random module because we wanted a random number that the user will be guessing.

Then, we assigned the “hidden” variable a random value between 1 and 1001. Note that, if you want to include 1000 in this range, then you’ll have to write 1001 as it doesn’t count.

We’ll need the user input to decide whether his/her answer is right or wrong. So we’ll assign that value to the variable “Guess”.

Finally, we’ll create if, elif and else statements to check whether the input is same as the random number.

3. Password Generator using Python – Easy and Fun

This one’s my favorite among all of these beginner Python projects. It’s a very simple and quick one.

So what it does is, take an input of how many characters you want and it will generate a password of that length.

This is how it will work

Time to code it:

import random
pass_len = int(input("Enter the length of the password: "))
pass_data = "qwertyuiopasdfgjklzxcvbnm1234567890[];',./[email protected]#$%^&*()_+:<>?"
password = "".join(random.sample(pass_data, pass_len))

It’s not at all complicated. Let me explain this one.


Whenever we want to work on a project, we first need to install the modules that are required. So here we need to install the random module. Why? Because we will need a password that consists of random values.

We need to get the user input for the length of characters they need in that password. So we’ll use the input() function. To store that input we’ll use the variable “pass_len“.

But did you notice that we’ve used the int() function? Because the input type will be an integer as the input we will get from the user will be a string, so we had to convert it to an integer.

Next, we created a string and assigned it to the variable “pass_data”. Now we’ll store all the values in this one like special characters etc,. Any value can be stored like numbers, alphabets etc. But for now, we’ll go with these ones.

And finally, we’ll join both of those variables to complete this easy project.

So the next one in beginner Python projects list is Email Slicer!

4. Email Slicer

What it does is return the username and the domain of a given email ID. So the input will be an email ID and the output will be the username and the domain.


email = input("Enter Your Email: ").strip()
username = email[:email.index('@')]
domain = email[email.index('@') + 1:]
print(f"Your username is {username} & domain is {domain}")


There is no setup required for this project so we just have to write our code.

So the user’s task is entering the email. Let’s first collect the user input. We know that input can be collected using the input() function. We’ll assign this input to the variable “email”.

Now you might have noticed strip() function in that code. What it does is, remove the spaces that are not wanted on both sides of the string. Now we’re left over with the only email as an input without any additional spaces.

Next, we are going to ignore the rest and slice the input of the user to get the domain and username.

In case of username variable we only want to keep the part of the string which comes before @ and ignore the rest.

Here we are making use of the slicing operator “:“and the index() function. index() function searches for the particular element or character within the string and lists it is associated with and return its index number.

Let’s consider the input is [email protected], so when we write email[:email.index('@')]i, our index() function will interpret it as email[:13] as our @ is located at index 13. Now email[:13] knows that @ is located at index 13, so now it will keep the part before index 13 and discard the rest.

This exact same process is followed for domain also.

We’ll be using the f-string, that will place the variables in the output string directly. Nothing to worry about if you have any doubt in these beginner python projects. Feel free to contact me.

Final Thoughts – Beginner Python Projects

Keep building more projects to master Python and I would recommend you to create some of your own.

I will update this post often and add more projects like these ones. Also, do not forget to subscribe to IOM because we’ll soon post a new series on Problem-solving using Python.

Stay tuned. Happy Coding!

Default image
Hi! I’m the creator of iqofmachines.com, a platform where I help beginners learn how to code. I’m here to share my favorite tools, resources, and strategies to help you learn the right tech skills faster.

Leave a Reply