Codementor Events

6 Python Projects for Beginners

Published May 01, 2020Last updated Oct 27, 2020
6 Python Projects for Beginners

Python can be a great programming language. You can make almost anything you want.
If you are a beginner and you don't know what to do, here are some beginner projects for you to make.

1-Basic Calculator

This is by far the easiest project in the list. You ask the user to put their first number, then the operator, then their second number. Once they put all of that, the program should calculate what the user wanted.

Things you should know to make this project:

  • variables
  • float
  • basic math
  • if/else if/ else
# The user's inputs for the numbers and the operators
num1 = float(input('Enter your first number: '))
Operator = input('Enter operator: ')
num2 = float(input('Enter your second number: '))

# if Operator is (+ | - | * | /) then print out number 1 (+ | - | * | /) number 2
if Operator == '+':
    print(num1 + num2)
elif Operator == '-':
    print(num1 - num2)
elif Operator == '/':
    print(num1 / num2)
elif Operator == '*':
    print(num1 * num2)

# if the user didn't put an operator
else:
    print('Invalid operator')

2-Guess the Number

This game is basic. The program chooses a random number. you can adjust how high or low the numbers can be (for example: 0-50 or 1-10.) It is all up to you.

Things you should know to make this project:

  • python random module
  • while loops
  • if/else if/else
  • integers
# Python Random Module
import random

# Number of Attempts
attempts = 0

# Choose a random number
number = random.randint(1, 20)
print("I am thinking of a number between 1 and 20.")

# While the player's guesses is less then 6
while attempts < 6:
    guess = input("Take a guess: ")
    guess = int(guess)

    attempts += 1

    # If the player's guess is too low
    if guess < number:
        print("Higher")

    # If the player's guess is too high
    if guess > number:
        print("Lower")
        
    # If the player won, stop the loop
    if guess == number:
        break

# If the player won
if guess == number:
    attempts = str(attempts)
    print(f"Good job! You guessed my number in {attempts} guesses!")

# If the player lost
if guess != number:
    number = str(number)
    print(f"Nope. The number I was thinking of was {number}")

3-Rock, Papers, Scissors

For me, this was the easiest game to make, The program randomly chooses rock, paper, or scissors. Then the player types his choice. Then... Well you know the rules.

Things you should know to make this project:

  • python random module
  • variables
  • if/else if/else
  • functions
  • lists
# Python Random Module
import random

# Intro
print("Rock, Paper, Scissors...")

# Function
def try_again():
  # Random Choice (Rock, Paper, or Scissors)
    R_P_S = ["Rock", "Paper", "Scissors"]
    computer = random.choice(R_P_S)

  # Player's choice
    player = input("your choice: ").lower().capitalize()

  # If the program chose rock
    if computer == "Rock":
    	# If the player chose rock
        if player == "Rock":
            print(f"I chose {computer}, you chose {player}\nit's a tie!")
        # If the player chose paper
        elif player == "Paper":
            print(f"I chose {computer}, you chose {player}\nYou win!")
        # If the player chose scissors
        elif player == "Scissors":
            print(f"I chose {computer}, you chose {player}\nI win!")

  # If the program chose paper
    elif computer == "Paper":
    	# If the player chose rock
        if player == "Rock":
            print(f"I chose {computer}, you chose {player}\nI win!")
        # If the player chose paper
        elif player == "Paper":
            print(f"I chose {computer}, you chose {player}\nIt's a tie!")
        # If the player chose scissors
        elif player == "Scissors":
            print(f"I chose {computer}, you chose {player}\nYou win!")

  # If the program chose scissors
    elif computer == "Scissors":
    	# If the player chose rock
        if player == "Rock":
            print(f"I chose {computer}, you chose {player}\nYou win!")
        # If the player chose paper
        elif player == "Paper":
            print(f"I chose {computer}, you chose {player}\nI win!")
        # If the player chose scissors
        elif player == "Scissors":
            print(f"I chose {computer}, you chose {player}\nIt's a tie") 

  # If the player wants to play again
    play_again = input("Do you want to play again? yes or no: ").lower().capitalize()
    # If the player says yes, go back to the function
    if play_again == "Yes":
        try_again()
    # If the player says no, say goodbye
    elif play_again == "No":
        print("Goodbye")

# End of function
try_again()

4-Roll The Dice

A program that acts like a virtual dice. You can make the user choose how many dices they want to roll (harder) or you can choose whatever you want and have the user to accept it (easier)

Things you chould know to make this project:

  • python random module
  • python playsound module (to make it more look like a virtual dice than some program that spits out random numbers)
  • variables
  • if/else if/else
  • while loop
  • functions
# Python Random & Playsound Modules
import random
from playsound import playsound

# Function
def again():
    dices = 0
    while dices == 0:
    	# User's choice of dices
        chosen_dices = int(input("How many dices do you want to roll: ")).lower()
        break
        
  # while the number of dices doesn't equal the user's choice, roll a dice
    while not chosen_dices == dices:
        if dices < 1:
            playsound('Dice shake.mp3')
            playsound("Dice roll.mp3")
        rolls = random.randint(1,6)
        print(rolls)
        dices +=1
    
    # if the user wants to try again
    while True:
    	try_again = input("would you like to throw again? (Yes, No)").lower()
        if try_again == "yes":
      		again()
        else:
        	return
# call the function
again()

5-Temperature Converter

A useful program to help you convert temperatures.

Things you should know to make this project:

  • python math module
  • python time module (I added it so that the user has time to read)
  • variables
  • float
  • intermediate math
  • knowledge about temperature (you can google it)
  • if/else if/else
# Python Math & Time Modules
import math
import time

# Intro
print("Welcome to the Temperature Conventer. Type C for Celsuis, F for Fahreinheit and K for Kelvin")

# Function
def again():
    try_again = print()
    # Letting the user choose the temperature and convert it to another temperature else
    User_Temperature = input("your temperature | C | F | K | ").upper()
    convert_Temperature = input("The temperature you want to convert to | C | F | K | ").upper()
  
    # If the user's intial temperature (C, F, or K) convert it to what the user wants to convert to (C, F, or K) and give him the equation
    if User_Temperature == "C":
        if convert_Temperature == "F":
            degree = float(input("enter the degree: "))
            result = (degree * 9/5) + 32
            print(f"{result}°F \nThe equation: ({degree} × 9/5) + 32 = {result}")
        elif convert_Temperature == "K":
            degree = float(input("enter the degree: "))
            result = degree + 273.15
            print(f"{result}°K \nThe equation: {degree} + 273.15 = {result}")
        elif convert_Temperature == "C":
            print("This is the same type of temperature")
            time.sleep(1)
            again()
        else:
            print("Type a temperature")
            time.sleep(1)
            again()

    elif User_Temperature == "F":
        if convert_Temperature == "C":
            degree = float(input("enter the degree: "))
            result = (degree - 32) * 5/9
            print(f"{result}°F \nThe equation: ({degree} - 32) × 5/9 = {result}")
        elif convert_Temperature == "K":
            degree = float(input("enter the degree: "))
            result = (degree - 32) * 5/9 + 273.15
            print(f"{result}°K \nThe equation: ({degree} - 32) × 5/9 + 273.15 = {result}")
        elif convert_Temperature == "F":
            print("This is the same type of temperature")
            time.sleep(1)
            again()
        else:
            print("Type a temperature")
            time.sleep(1)
            again()

    elif User_Temperature == "K":
        if convert_Temperature == "C":
            degree = float(input("enter the degree: "))
            result = degree - 273.15
            print(f"{result}°F \nThe equation: {degree} - 273.15 = {result}")
        elif convert_Temperature == "F":
            degree = float(input("enter the degree: "))
            result = (degree - 273.15) * 9/5 + 32
            print(f"{result}°K \nThe equation: ({degree} - 273.15) × 9/5 + 32 = {result}")
        elif convert_Temperature == "K":
            print("This is the same type of temperature")
            time.sleep(1)
            again()
        else:
            print("Type a temperature")
            time.sleep(1)
            again()

    else:
        print("Type a temperature")
        time.sleep(1)
        again()

  # Aking if the user wants to convert again
    while try_again != "Yes" and try_again != "No":
        print("\nDo you want to try again?")
        try_again = input("Yes | No | ").lower().capitalize()
        if try_again == "Yes":
            again()
            break
        elif try_again == "No":
            print("Goodbye")
            break

again()

6-Hangman

This by far might take the longest to make, depending on how many words you put.
The program chooses a random word from the list, then the program prints out some letters and asks the user to type the missing letters. After 6 attempts, the player loses. I'll only put 1 word so that you get the idea and the script won't be long.

Things you need to know to make this project:

  • python random module
  • functions
  • lists
  • variables
  • if/else if/else
# Python Random Module
import random

# Intro
print("Welcome to Hangman! I will choose a word and you have to guess its letters. You only have 6 attempts.")

# Function
def try_again():
  # Random chooser
    words = ["ignore"]
    word_choice = random.choice(words)
    
    # Variables
    attempts = 0
    a = False
    b = False
    c = False
    d = False
    e = False
    f = False
    g = False
    h = False
    i = False
    j = False
    k = False
    l = False
    m = False
    n = False
    o = False
    p = False
    q = False
    r = False
    s = False
    t = False
    u = False
    v = False
    w = False
    x = False
    y = False
    z = False

  # If the program chose a word, print it out with missing letters. If the user gets the letters correct, change its variable to True and print it out. Once all the letters are found, the player won
    if word_choice == "ignore":
        print(" ____ n o __ e")
        guess = input("type the missing letter: ")
        while attempts < 6:
            if guess == "i":
                i=True
                if g == True and r == True:
                    print("i g n o r e")
                    win = input(f"you won, you took {attempts} attempt(s), Do you want to play again? Yes or No: ").lower().capitalize()
                    if win == "Yes":
                        try_again()
                        break
                    elif win == "No":
                        print("Goodbye")
                        break
                elif r == True:
                    print("i __ n o r e")
                    guess = input("\ntype the missing letter: ")
                elif g == True:
                    print("i g n o __ e")
                    guess = input("\ntype the missing letter: ")
                else:
                    print("i __n o__ e")
                    guess = input("\ntype the missing letter: ")
            elif guess == "g":
                g = True
                if i == True and r == True:
                    print("i g n o r e")
                    win = input(f"you won, you took {attempts} attempt(s), Do you want to play again? Yes or No: ").lower().capitalize()
                    if win == "Yes":
                        try_again()
                        break
                    elif win == "No":
                        print("Goodbye")
                        break
                elif r == True:
                    print("__ g n o r e")
                    guess = input("\ntype the missing letter: ")
                elif i == True:
                    print("i g n o __ e")
                    guess = input("\ntype the missing letter: ")
                else:
                    print(" __g n o__ e")
                    guess = input("\ntype the missing letter: ")
            elif guess == "r":
                r = True
                if i == True and g == True:
                    print("i g n o r e")
                    win = input(f"you won, you took {attempts} attempt(s), Do you want to play again? Yes or No: ").lower().capitalize()
                    if win == "Yes":
                        try_again()
                        break
                    elif win == "No":
                        print("Goodbye")
                        break
                elif g == True:
                    print("__ g n o r e")
                    guess = input("\ntype the missing letter: ")
                elif i == True:
                    print("i __ n o r e")
                else:
                    print(" ____ n o r e")
                    guess = input("\ntype the missing letter: ")
            else:
                print("Try Again")
                attempts += 1
                guess = input("\ntype the missing letter: ")
    		
            # If all of the player's attempts lost, game over
            if not attempts < 6:
            	game_over = input("Game Over. Do you want to play again? Yes or No: ").lower().capitalize()
                if game_over == "Yes":
                	try_again()
                elif game_over == "No":
                    print("Goodbye")

# End of function
try_again()

I hope this helps you, please comment out your programs to let everyone see it.

Discover and read more posts from Abdullah Alawad
get started
post comments8Replies
Neeraj Singh
4 years ago

Thanks for sharing

Abdullah Alawad
4 years ago

Roll the dice updated, now has an infinite amount of throws

Joshua McGowan
5 years ago

This is awesome. Thx!

Abdullah Alawad
5 years ago

welcome

Show more replies