Codementor Events

6 Python Projects For Beginners

Published Sep 09, 2019Last updated Apr 22, 2020
6 Python Projects For Beginners

So, you’ve just finished learning the basics of Python. The question now is, what do you do now? How can you continue to keep developing your coding skills using Python? Do you carry on watching tutorials, or is there something better you can do? The answer is yes there is something better, and that something is working on your own python project. Here are 6 small Python projects you can do as a beginner.

Guess The Number

Write a programme where the computer randomly generates a number between 0 and 20. The user needs to guess what the number is. If the user guesses wrong, tell them their guess is either too high, or too low. This will get you started with the random library if you haven't already used it.

Rock, Paper, Scissors Game

Make a rock-paper-scissors game where it is the player vs the computer. The computer’s answer will be randomly generated, while the program will ask the user for their input. This project will better your understanding of while loops and if statements.

Generating a sine vs cosine curve

For this project, you will have a generate a sine vs cosine curve. You will need to use the numpy library to access the sine and cosine functions. You will also need to use the matplotlib library to draw the curve. To make this more difficult, make the graph go from -360° to 360°, with there being a 180° difference between each point on the x-axis.

Password Generator

Write a programme, which generates a random password for the user. Ask the user how long they want their password to be, and how many letters and numbers they want in their password. Have a mix of upper and lowercase letters, as well as numbers and symbols. The password should be a minimum of 6 characters long.

Hangman

This is probably the hardest one out of these 6 small projects. This will be similar to guessing the number, except we are guessing the word. The user needs to guess letters,
Give the user no more than 6 attempts for guessing wrong letter. This will mean you will have to have a counter. You can download a ‘sowpods’ dictionary file or csv file to use as a way to get a random word to use.

Binary Search Algorithm

Create a random list of numbers between 0 and 100 with a difference of 2 between each number. Ask the user for a number between 0 and 100 to check whether their number is in the list. The programme should work like this. The programme will half the list of numbers and see whether the users number matches the middle element in the list. If they do not match, the programme will check which half the number lies in, and eliminate the other half. The search then continues on the remaining half, again checking whether the middle element in that half is equal to the user’s number. This process keeps on going until the programme finds the users number, or until the size of the subarray is 0, which means the users number isn't in the list.

If you are struggling with any of these, then feel free to message me, or just have a look online as there are plenty of solutions available on platforms such as youtube.

Discover and read more posts from Ilyaas Lunat
get started
post comments131Replies
ABDOU alpha_dz
4 years ago

Two ways to solve Binary Search Algorithm :

Test array

arr = [ 2, 3, 4, 10, 40 ]
x = 10

if x in arr:
for y in range(len(arr)):
if arr[y] == x:
print("Element is present at index ", y)
else:
print(“Element is not present in the array”)

if x in arr:
for index, item in enumerate(arr):
if item == x:
print("Element is present at index ", index)
else:
print(“Element is not present in the array”)

HANGMAN :

Hangman game

def gameplay():
secret_word = input(“Player one, please enter your secret word : “)
for w in range(50):
print(w*””)
secret = “_” * len(secret_word)
secret = list(secret)
print("Player 2 must guess Player’s one’s guess ")
current_progress = “”
failed_guesses = 0
while current_progress != secret_word:
guess = input("Player 2, please guess a letter : ")
if guess in secret_word:
for i in range(len(secret_word)):
if secret_word[i] == guess:
secret[i] = guess
final = “”
for x in secret:
final += x

        print("Current progress : ", final)
        if secret_word == final :
            print("You won!!!")    
            break
    
    else:
        failed_guesses += 1
        print("You guess is incorrect, please try again!")
        print("Hangman status : ", end="")
        
        if failed_guesses == 1:
            print("O")
        elif failed_guesses == 2:
            print("0-")
        elif failed_guesses == 3:
            print("0_0")
        elif failed_guesses == 4:
            print("0-<")
        elif failed_guesses == 5:
            print("0+<")
        elif failed_guesses == 6:
            print("You died!!")
            
        print("Number of chances left : ", 6-failed_guesses)
        for p in range(2):
            print(p*"")
        if failed_guesses == 6:
            print("You lost!!")
            break
        

print("Thank you for playing hangman!")

gameplay()

Shakeel Ahmed
4 years ago

I made an enhanced version of the Number Guessing Game with 2 play modes and a way better UI. Check it out: https://github.com/ShakeelAhmed123/Simple-Python-Number-Guessing-Game

imad chafik
4 years ago

HELLO WORLD !! PLEASE CORRECT ME, I SOLVED EM ALL:

###THE BINARY SEARCH ALGO

import random
def div(l):
if len(l) %2 == 0:
B =[]
for k in range(0,int(len(l)/2)):
B.append(l[k])
S = []
for i in range(int(len(l)/2)+1,len(l)):
S.append(l[i])

    return [S ,B]
if len(l)%2 ==1:
    H1 = []
    for k in range(0,int(len(l)/2)+1):
        H1.append(l[k])
    H2 = []
    for i in range(int(len(l)/2)+1,len(l)):
        H2.append(l[i])
    return [H1,H2]

def inhalf(n, L):
if n in L[0]:
return L[0]
if n in L[1]:
return L[1]
def cent(L):
return L[int(len(L)/2)+1]

R = [k for k in range(0,101)]
R = random.sample(R,101)
print®

u = int(input(“HEY! guess a number between 0 and 100”))
print(“I generated a random list of numbers between 0 and 100”)
if u == cent® :
print(“U WON , IT WAS IN THE MIDDLE OF MY RLIST {}”.format(u))
else :

while u in inhalf(u,div(R)) and len(R)> 2:
    R = inhalf(u,div(R))
    print("we found it in here")
    print(R)

cos vs sin (I am not sure i understood well what is asked

import numpy as np
import matplotlib.pyplot as plt

X = np.linspace(-2np.pi,2np.pi,100)
Y = np.cos(X)
Z = np.sin(X)

plt.plot(X,Y)

plt.plot(X,Z)
plt.show()

###guess a number

import random
a = random.randint(0,20)
b = int(input(“guess a number between zero and twenty”))
if b==a :
print(“good guess”)
while a != b :
if b<a :
print(“too small”)
b = int(input(“guess again”))

if b>a :
    print("too high")
    b = int(input("guess again"))
if b==a :
    print("good guess")

hangman

import random

while input(“wanna play ?”) == “yes”:
#convert the word to a list of letters
def Convert(string):
list1=[]
list1[:0]=string

    return list1
#choose the random word
with open('sowpods.txt') as f:
    words = list(f)
    word = random.choice(words).strip()
L = Convert(word)
U = [0 for x in range(1,len(L)+1)]
print(L)
print(U)
l = len(L)
#the interaction u/c
print("welcome to hungman, the word i have in mind counts :{} letters".format(l))
print("u have the right to make 6 wrong guesses")
cp = 0

while cp < 7 and U != L:
    u = input("enter a letter")
    if u not in L:
        cp +=1
        print("false")
    if cp == 7: 
        print("GAME OVER LOOOOSER, U are hunged motherfucker")
    else:
        k = 0
        p = 0
        while k != l:
            for i in range (0,l):
                if L[i] != u :
                    k+=1
                else : 
                    print("the letter u gave is in the : {}position" .format(k+1))  
                    U[k] = u
                    print(U)
                    k += 1
                
        if L == U:
            print("GOOD JOB DUM DUM !! the word was : "+ str(word))

password generator

import string
import numpy as np
import random
Le = string.ascii_letters
Nu = [“0”,“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”]

Python code to convert string to list character-wise

def Convert(string):
list1=[]
list1[:0]=string
return list1

le = Convert(Le)
nu = Convert(Nu)

Python program to convert a list to string

Function to convert

def listToString(s):

# initialize an empty string 
str1 = ""  

# traverse in the string   
for ele in s:  
    str1 += ele   

# return string   
return str1 

def password(L,N):
l = []
n = []
if N + L <6:
print(“error, the password must contain at least 6 carac”)
else :

    while len(l) != L:
        l.append(random.choice(le))
    print(l)
    
    while len(n) != N:
        n.append(random.choice(nu))
    print(n)

    f = random.sample(n+l,len(n+l))
    return str(listToString(f))

rock,scissor,paper

import random
L = [“rock”, “scissor”,“paper”]
u = str(input(“let’s play ! Wanna start ?”))
while u != “no”:

value = str(input("rock,scissor,paper"))
c = random.choice(L)
print(c)
if c == value:
    print("we're even")
if c == L[0] and value == L[1] or c == L[1] and  value == L[2] or c == L[2] and value == L[0] :
    print("I won")
if c == L[0] and value == L[2] or c == L[2] and value == L[1] or value == L[0] and c == L[1]:
    print("u won")
ggggggggggg
4 years ago

Password thing don’t work iss useless

John Die
4 years ago

Yes it does. You need to import the random module. I have built one before, using Tkinter.

Show more replies