The very important question is – What should i build with Python?
nitially, it’s important to recognize the extensive range of Python applications across various fields, offering numerous options for exploration.
Certainly, Python has earned a robust standing in domains such as data science, data analysis, machine learning, and artificial intelligence (AI). However, its versatility extends beyond these realms.
Python excels in web development, owing to the presence of well-regarded web application frameworks like Django and Flask.
Furthermore, Python proves to be highly effective in automating repetitive tasks, aligning with its roots as a scripting language. This inherent capability makes it an ideal choice for streamlining processes and increasing efficiency.
Let’s explore 10 python projects which you can make if you are a Beginner.
Python Projects for Beginners
- Number Guessing
- Mad Libs Generator
- Rock Paper Scissors
- Dice Roll Generator
- Hangman Game
- Password Strength Checker
- Number to Words
- Tic-Tac-Toe Game
- Calculator
- Countdown Clock and Timer
Number Guessing:
This introductory Python project offers an entertaining game where a random number within a specified range is generated. The user is tasked with guessing the number based on provided hints. With each incorrect guess, users receive additional hints, albeit at the expense of their final score.
This project provides an excellent opportunity to explore the Python standard library. It leverages the capabilities of the Python random module for generating random numbers, making it a valuable exercise for experimenting with library functions.
'''
Number Guessing Game
-------------------------------------------------------------
'''
import random
def show_score(attempts_list):
if not attempts_list:
print('There is currently no best score,'
' it\'s yours for the taking!')
else:
print(f'The current best score is'
f' {min(attempts_list)} attempts')
def start_game():
attempts = 0
rand_num = random.randint(1, 10)
attempts_list = []
print('Hello traveler! Welcome to the game of guesses!')
player_name = input('What is your name? ')
wanna_play = input(
f'Hi, {player_name}, would you like to play '
f'the guessing game? (Enter Yes/No): ')
if wanna_play.lower() != 'yes':
print('That\'s cool, Thanks!')
exit()
else:
show_score(attempts_list)
while wanna_play.lower() == 'yes':
try:
guess = int(input('Pick a number between 1 and 10: '))
if guess < 1 or guess > 10:
raise ValueError(
'Please guess a number within the given range')
attempts += 1
if guess == rand_num:
attempts_list.append(attempts)
print('Nice! You got it!')
print(f'It took you {attempts} attempts')
wanna_play = input(
'Would you like to play again? (Enter Yes/No): ')
if wanna_play.lower() != 'yes':
print('That\'s cool, have a good one!')
break
else:
attempts = 0
rand_num = random.randint(1, 10)
show_score(attempts_list)
continue
else:
if guess > rand_num:
print('It\'s lower')
elif guess < rand_num:
print('It\'s higher')
except ValueError as err:
print('Oh no!, that is not a valid value. Try again...')
print(err)
if __name__ == '__main__':
start_game()
Mad Libs Generator:
This beginner Python project is both enjoyable and educational, providing a practical opportunity to hone skills in working with strings, variables, and concatenation. These skills are fundamental for any Python application, regardless of skill level.
The Mad Libs Generator involves the collection and manipulation of user input data, specifically adjectives, pronouns, and verbs. The program then utilizes this input to construct a creative and dynamic story, offering a hands-on way to reinforce key Python concepts.
'''
Mad Libs Generator
-------------------------------------------------------------
'''
# Questions for the user to answer
noun = input('Choose a noun: ')
p_noun = input('Choose a plural noun: ')
noun2 = input('Choose a noun: ')
place = input('Name a place: ')
adjective = input('Choose an adjective (Describing word): ')
noun3 = input('Choose a noun: ')
# Print a story from the user input
print('------------------------------------------')
print('Be kind to your', noun, '- footed', p_noun)
print('For a duck may be somebody\'s', noun2, ',')
print('Be kind to your', p_noun, 'in', place)
print('Where the weather is always', adjective, '. \n')
print('You may think that is this the', noun3, ',')
print('Well it is.')
print('------------------------------------------')
Rock Paper Scissor:
This Rock Paper Scissors program serves as a simulation of the widely popular game, incorporating functions and conditional statements. It’s an excellent means of mastering these crucial programming concepts. Additionally, the project involves utilizing Python lists to store valid responses, enabling the creation of elegant and Pythonic conditional statements.
As one among numerous Python coding projects integrating external libraries, this program incorporates modules from the standard library, including random, os, and re.
Examining the code below, you’ll observe that this Python project invites the user to initiate the game by providing a character representing rock, paper, or scissors. Following the evaluation of the input string, the conditional logic systematically checks for a winner.
'''
Rock Paper Scissors
-------------------------------------------------------------
'''
import random
import os
import re
def check_play_status():
valid_responses = ['yes', 'no']
while True:
try:
response = input('Do you wish to play again? (Yes or No): ')
if response.lower() not in valid_responses:
raise ValueError('Yes or No only')
if response.lower() == 'yes':
return True
else:
os.system('cls' if os.name == 'nt' else 'clear')
print('Thanks for playing!')
exit()
except ValueError as err:
print(err)
def play_rps():
play = True
while play:
os.system('cls' if os.name == 'nt' else 'clear')
print('')
print('Rock, Paper, Scissors - Shoot!')
user_choice = input('Choose your weapon'
' [R]ock], [P]aper, or [S]cissors: ')
if not re.match("[SsRrPp]", user_choice):
print('Please choose a letter:')
print('[R]ock, [P]aper, or [S]cissors')
continue
print(f'You chose: {user_choice}')
choices = ['R', 'P', 'S']
opp_choice = random.choice(choices)
print(f'I chose: {opp_choice}')
if opp_choice == user_choice.upper():
print('Tie!')
play = check_play_status()
elif opp_choice == 'R' and user_choice.upper() == 'S':
print('Rock beats scissors, I win!')
play = check_play_status()
elif opp_choice == 'S' and user_choice.upper() == 'P':
print('Scissors beats paper! I win!')
play = check_play_status()
elif opp_choice == 'P' and user_choice.upper() == 'R':
print('Paper beats rock, I win!')
play = check_play_status()
else:
print('You win!\n')
play = check_play_status()
if __name__ == '__main__':
play_rps()
Dice Roll Generator:
This Python project, which involves simulating the rolling of one or two dice, stands out as a relatable and engaging option for beginners. It provides a practical avenue to reinforce your comprehension of user-defined functions, loops, and conditional statements – foundational skills essential for novice Python programmers. Whether acquired through online courses or Python literature, these skills often mark the initial stages of learning.
Considered one of our straightforward Python projects, this program employs the Python random module to emulate the unpredictable outcomes of dice rolls. Additionally, the os module is utilized to clear the screen after each roll.
It’s worth noting that the maximum dice value is customizable, offering the flexibility to simulate polyhedral dice commonly used in various board and roleplaying games.
Dice Roll Generator
-------------------------------------------------------------
'''
import random
import os
def num_die():
while True:
try:
num_dice = input('Number of dice: ')
valid_responses = ['1', 'one', 'two', '2']
if num_dice not in valid_responses:
raise ValueError('1 or 2 only')
else:
return num_dice
except ValueError as err:
print(err)
def roll_dice():
min_val = 1
max_val = 6
roll_again = 'y'
while roll_again.lower() == 'yes' or roll_again.lower() == 'y':
os.system('cls' if os.name == 'nt' else 'clear')
amount = num_die()
if amount == '2' or amount == 'two':
print('Rolling the dice...')
dice_1 = random.randint(min_val, max_val)
dice_2 = random.randint(min_val, max_val)
print('The values are:')
print('Dice One: ', dice_1)
print('Dice Two: ', dice_2)
print('Total: ', dice_1 + dice_2)
roll_again = input('Roll Again? ')
else:
print('Rolling the die...')
dice_1 = random.randint(min_val, max_val)
print(f'The value is: {dice_1}')
roll_again = input('Roll Again? ')
if __name__ == '__main__':
roll_dice()
Hangman Game:
This Python project presents an entertaining idea—recreating the classic word-guessing game, Hangman. While we’ve incorporated a predetermined list of words for guessing, you have the flexibility to enhance the experience by incorporating a third-party dictionary API.
The implementation of loops, functions, and string formatting in this Python project allows for the visualization of the hangman’s progress. Additionally, it provides an opportunity to explore the functionalities of Python’s standard library, including the random, time, and os modules.
In particular, the random module is employed to select the word for guessing, the os module facilitates screen clearing, and the time module’s .sleep() function introduces pauses to improve the overall flow of the game.
Hangman Game
-------------------------------------------------------------
'''
import random
import time
import os
def play_again():
question = 'Do You want to play again? y = yes, n = no \n'
play_game = input(question)
while play_game.lower() not in ['y', 'n']:
play_game = input(question)
if play_game.lower() == 'y':
return True
else:
return False
def hangman(word):
display = '_' * len(word)
count = 0
limit = 5
letters = list(word)
guessed = []
while count < limit:
guess = input(f'Hangman Word: {display} Enter your guess: \n').strip()
while len(guess) == 0 or len(guess) > 1:
print('Invalid input. Enter a single letter\n')
guess = input(
f'Hangman Word: {display} Enter your guess: \n').strip()
if guess in guessed:
print('Oops! You already tried that guess, try again!\n')
continue
if guess in letters:
letters.remove(guess)
index = word.find(guess)
display = display[:index] + guess + display[index + 1:]
else:
guessed.append(guess)
count += 1
if count == 1:
time.sleep(1)
print(' _____ \n'
' | \n'
' | \n'
' | \n'
' | \n'
' | \n'
' | \n'
'__|__\n')
print(f'Wrong guess: {limit - count} guesses remaining\n')
elif count == 2:
time.sleep(1)
print(' _____ \n'
' | | \n'
' | | \n'
' | \n'
' | \n'
' | \n'
' | \n'
'__|__\n')
print(f'Wrong guess: {limit - count} guesses remaining\n')
elif count == 3:
time.sleep(1)
print(' _____ \n'
' | | \n'
' | | \n'
' | | \n'
' | \n'
' | \n'
' | \n'
'__|__\n')
print(f'Wrong guess: {limit - count} guesses remaining\n')
elif count == 4:
time.sleep(1)
print(' _____ \n'
' | | \n'
' | | \n'
' | | \n'
' | O \n'
' | \n'
' | \n'
'__|__\n')
print(f'Wrong guess: {limit - count} guesses remaining\n')
elif count == 5:
time.sleep(1)
print(' _____ \n'
' | | \n'
' | | \n'
' | | \n'
' | O \n'
' | /|\ \n'
' | / \ \n'
'__|__\n')
print('Wrong guess. You\'ve been hanged!!!\n')
print(f'The word was: {word}')
if display == word:
print(f'Congrats! You have guessed the word \'{word}\' correctly!')
break
def play_hangman():
print('\nWelcome to Hangman\n')
name = input('Enter your name: ')
print(f'Hello {name}! Best of Luck!')
time.sleep(1)
print('The game is about to start!\nLet\'s play Hangman!')
time.sleep(1)
os.system('cls' if os.name == 'nt' else 'clear')
words_to_guess = [
'january', 'border', 'image', 'film', 'promise', 'kids',
'lungs', 'doll', 'rhyme', 'damage', 'plants', 'hello', 'world'
]
play = True
while play:
word = random.choice(words_to_guess)
hangman(word)
play = play_again()
print('Thanks For Playing! We expect you back again!')
exit()
if __name__ == '__main__':
play_hangman()
Password Strength Checker:
Exploring the realm of app development, this Python project offers an excellent opportunity to assess the strength of your passwords.
The project accomplishes this by evaluating the count of letters, numbers, special characters, and whitespace characters in a given password, subsequently assigning a score based on these criteria. Thus, it becomes a valuable learning experience for grasping conditional statements, functions, and string formatting.
In addition, the implementation utilizes the string and getpass modules from the Python standard library. Leveraging these modules enables access to a comprehensive range of string characters for comparison with the password’s composition. The .getpass() function is particularly employed to conceal the password during entry, enhancing security.
Password Strength Checker
-------------------------------------------------------------
'''
import string
import getpass
def check_password_strength():
password = getpass.getpass('Enter the password: ')
strength = 0
remarks = ''
lower_count = upper_count = num_count = wspace_count = special_count = 0
for char in list(password):
if char in string.ascii_lowercase:
lower_count += 1
elif char in string.ascii_uppercase:
upper_count += 1
elif char in string.digits:
num_count += 1
elif char == ' ':
wspace_count += 1
else:
special_count += 1
if lower_count >= 1:
strength += 1
if upper_count >= 1:
strength += 1
if num_count >= 1:
strength += 1
if wspace_count >= 1:
strength += 1
if special_count >= 1:
strength += 1
if strength == 1:
remarks = ('That\'s a very bad password.'
' Change it as soon as possible.')
elif strength == 2:
remarks = ('That\'s a weak password.'
' You should consider using a tougher password.')
elif strength == 3:
remarks = 'Your password is okay, but it can be improved.'
elif strength == 4:
remarks = ('Your password is hard to guess.'
' But you could make it even more secure.')
elif strength == 5:
remarks = ('Now that\'s one hell of a strong password!!!'
' Hackers don\'t have a chance guessing that password!')
print('Your password has:-')
print(f'{lower_count} lowercase letters')
print(f'{upper_count} uppercase letters')
print(f'{num_count} digits')
print(f'{wspace_count} whitespaces')
print(f'{special_count} special characters')
print(f'Password Score: {strength / 5}')
print(f'Remarks: {remarks}')
def check_pwd(another_pw=False):
valid = False
if another_pw:
choice = input(
'Do you want to check another password\'s strength (y/n) : ')
else:
choice = input(
'Do you want to check your password\'s strength (y/n) : ')
while not valid:
if choice.lower() == 'y':
return True
elif choice.lower() == 'n':
print('Exiting...')
return False
else:
print('Invalid input...please try again. \n')
if __name__ == '__main__':
print('===== Welcome to Password Strength Checker =====')
check_pw = check_pwd()
while check_pw:
check_password_strength()
check_pw = check_pwd(True)
Number to Words:
This Python project concept transforms an integer obtained through user input into its corresponding word representation. While the program is initially designed to handle numbers with up to 12 digits, you have the flexibility to adapt it for larger numbers by incorporating conditional statements and loops.
Serving as an accessible example of fundamental Python projects, this uncomplicated yet impactful program enhances your proficiency with loops, user input, conditional statements, and introduces you to Python tuples and lists.
Furthermore, the project allows you to delve into mathematical operations, introducing you to concepts such as the modulo (%) operator, which calculates the remainder from integer division.
For those unfamiliar with these techniques, consider incorporating an AI coding assistant into your Python IDE. This tool can provide assistance and guidance for any challenging code blocks you encounter, facilitating a smoother learning process.
Numbers To Words
-------------------------------------------------------------
'''
ones = (
'Zero', 'One', 'Two', 'Three', 'Four',
'Five', 'Six', 'Seven', 'Eight', 'Nine'
)
twos = (
'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen',
'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen'
)
tens = (
'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty',
'Seventy', 'Eighty', 'Ninety', 'Hundred'
)
suffixes = (
'', 'Thousand', 'Million', 'Billion'
)
def fetch_words(number, index):
if number == '0': return 'Zero'
number = number.zfill(3)
hundreds_digit = int(number[0])
tens_digit = int(number[1])
ones_digit = int(number[2])
words = '' if number[0] == '0' else ones[hundreds_digit]
if words != '':
words += ' Hundred '
if tens_digit > 1:
words += tens[tens_digit - 2]
words += ' '
words += ones[ones_digit]
elif(tens_digit == 1):
words += twos[((tens_digit + ones_digit) % 10) - 1]
elif(tens_digit == 0):
words += ones[ones_digit]
if(words.endswith('Zero')):
words = words[:-len('Zero')]
else:
words += ' '
if len(words) != 0:
words += suffixes[index]
return words
def convert_to_words(number):
length = len(str(number))
if length > 12:
return 'This program supports a maximum of 12 digit numbers.'
count = length // 3 if length % 3 == 0 else length // 3 + 1
copy = count
words = []
for i in range(length - 1, -1, -3):
words.append(fetch_words(
str(number)[0 if i - 2 < 0 else i - 2 : i + 1], copy - count))
count -= 1
final_words = ''
for s in reversed(words):
final_words += (s + ' ')
return final_words
if __name__ == '__main__':
number = int(input('Enter any number: '))
print('%d in words is: %s' %(number, convert_to_words(number)))
Tic-Tac-Toe Game:
Tic-Tac-Toe is a classic game where two players take turns marking spaces on a grid with either an O or an X. The goal is to get three of your marks in a row, either horizontally, vertically, or diagonally, before your opponent does. The catch is that you also have to strategically block your opponent from achieving the same.
This Python project is both enjoyable and special for beginners because it introduces the concept of object-oriented programming. In simpler terms, it involves creating a new “class” named TicTacToe to represent the game’s features, using this class to define attributes and methods.
By examining these methods, you’ll see how object-oriented programming allows us to neatly organize the various actions needed to simulate the game.
In this beginner-friendly Python project, you’ll encounter new elements like nested loops, which are used to check the grid for winning combinations in columns, rows, and diagonals. The program also utilizes the Python set data type to handle unique values. Additionally, the Python random module is employed to randomly determine which player starts the game – a concept you should be more familiar with by now.
Tic Tac Toe
-------------------------------------------------------------
'''
import random
class TicTacToe:
def __init__(self):
self.board = []
def create_board(self):
for i in range(3):
row = []
for j in range(3):
row.append('-')
self.board.append(row)
def get_random_first_player(self):
return random.randint(0, 1)
def fix_spot(self, row, col, player):
self.board[row][col] = player
def has_player_won(self, player):
n = len(self.board)
board_values = set()
# check rows
for i in range(n):
for j in range(n):
board_values.add(self.board[i][j])
if board_values == {player}:
return True
else:
board_values.clear()
# check cols
for i in range(n):
for j in range(n):
board_values.add(self.board[j][i])
if board_values == {player}:
return True
else:
board_values.clear()
# check diagonals
for i in range(n):
board_values.add(self.board[i][i])
if board_values == {player}:
return True
else:
board_values.clear()
board_values.add(self.board[0][2])
board_values.add(self.board[1][1])
board_values.add(self.board[2][0])
if board_values == {player}:
return True
else:
return False
def is_board_filled(self):
for row in self.board:
for item in row:
if item == '-':
return False
return True
def swap_player_turn(self, player):
return 'X' if player == 'O' else 'O'
def show_board(self):
for row in self.board:
for item in row:
print(item, end=' ')
print()
def start(self):
self.create_board()
player = 'X' if self.get_random_first_player() == 1 else 'O'
game_over = False
while not game_over:
try:
self.show_board()
print(f'\nPlayer {player} turn')
row, col = list(
map(int, input(
'Enter row & column numbers to fix spot: ').split()))
print()
if col is None:
raise ValueError(
'not enough values to unpack (expected 2, got 1)')
self.fix_spot(row - 1, col - 1, player)
game_over = self.has_player_won(player)
if game_over:
print(f'Player {player} wins the game!')
continue
game_over = self.is_board_filled()
if game_over:
print('Match Draw!')
continue
player = self.swap_player_turn(player)
except ValueError as err:
print(err)
print()
self.show_board()
if __name__ == '__main__':
tic_tac_toe = TicTacToe()
tic_tac_toe.start()
Calculator:
This straightforward Python project involves building a simple calculator application that performs addition, subtraction, multiplication, and division operations.
It serves as an excellent practice project for honing skills in using loops, functions, conditional statements, user input, and string formatting in Python. The program also incorporates the Python os module to clear the screen after the user finishes their calculation tasks.
Once you grasp the fundamental concepts through this project, explore opportunities to enhance its functionality by adding features like exponentiation or tackling more intricate calculations.
Calculator
-------------------------------------------------------------
'''
import os
def addition():
os.system('cls' if os.name == 'nt' else 'clear')
print('Addition')
continue_calc = 'y'
num_1 = float(input('Enter a number: '))
num_2 = float(input('Enter another number: '))
ans = num_1 + num_2
values_entered = 2
print(f'Current result: {ans}')
while continue_calc.lower() == 'y':
continue_calc = (input('Enter more (y/n): '))
while continue_calc.lower() not in ['y', 'n']:
print('Please enter \'y\' or \'n\'')
continue_calc = (input('Enter more (y/n): '))
if continue_calc.lower() == 'n':
break
num = float(input('Enter another number: '))
ans += num
print(f'Current result: {ans}')
values_entered += 1
return [ans, values_entered]
def subtraction():
os.system('cls' if os.name == 'nt' else 'clear')
print('Subtraction')
continue_calc = 'y'
num_1 = float(input('Enter a number: '))
num_2 = float(input('Enter another number: '))
ans = num_1 - num_2
values_entered = 2
print(f'Current result: {ans}')
while continue_calc.lower() == 'y':
continue_calc = (input('Enter more (y/n): '))
while continue_calc.lower() not in ['y', 'n']:
print('Please enter \'y\' or \'n\'')
continue_calc = (input('Enter more (y/n): '))
if continue_calc.lower() == 'n':
break
num = float(input('Enter another number: '))
ans -= num
print(f'Current result: {ans}')
values_entered += 1
return [ans, values_entered]
def multiplication():
os.system('cls' if os.name == 'nt' else 'clear')
print('Multiplication')
continue_calc = 'y'
num_1 = float(input('Enter a number: '))
num_2 = float(input('Enter another number: '))
ans = num_1 * num_2
values_entered = 2
print(f'Current result: {ans}')
while continue_calc.lower() == 'y':
continue_calc = (input('Enter more (y/n): '))
while continue_calc.lower() not in ['y', 'n']:
print('Please enter \'y\' or \'n\'')
continue_calc = (input('Enter more (y/n): '))
if continue_calc.lower() == 'n':
break
num = float(input('Enter another number: '))
ans *= num
print(f'Current result: {ans}')
values_entered += 1
return [ans, values_entered]
def division():
os.system('cls' if os.name == 'nt' else 'clear')
print('Division')
continue_calc = 'y'
num_1 = float(input('Enter a number: '))
num_2 = float(input('Enter another number: '))
while num_2 == 0.0:
print('Please enter a second number > 0')
num_2 = float(input('Enter another number: '))
ans = num_1 / num_2
values_entered = 2
print(f'Current result: {ans}')
while continue_calc.lower() == 'y':
continue_calc = (input('Enter more (y/n): '))
while continue_calc.lower() not in ['y', 'n']:
print('Please enter \'y\' or \'n\'')
continue_calc = (input('Enter more (y/n): '))
if continue_calc.lower() == 'n':
break
num = float(input('Enter another number: '))
while num == 0.0:
print('Please enter a number > 0')
num = float(input('Enter another number: '))
ans /= num
print(f'Current result: {ans}')
values_entered += 1
return [ans, values_entered]
def calculator():
quit = False
while not quit:
results = []
print('Simple Calculator in Python!')
print('Enter \'a\' for addition')
print('Enter \'s\' for substraction')
print('Enter \'m\' for multiplication')
print('Enter \'d\' for division')
print('Enter \'q\' to quit')
choice = input('Selection: ')
if choice == 'q':
quit = True
continue
if choice == 'a':
results = addition()
print('Ans = ', results[0], ' total inputs: ', results[1])
elif choice == 's':
results = subtraction()
print('Ans = ', results[0], ' total inputs: ', results[1])
elif choice == 'm':
results = multiplication()
print('Ans = ', results[0], ' total inputs: ', results[1])
elif choice == 'd':
results = division()
print('Ans = ', results[0], ' total inputs: ', results[1])
else:
print('Sorry, invalid character')
if __name__ == '__main__':
calculator()
Countdown Clock and Timer:
This Python project concept is quite enjoyable! In this instance, we’ve developed a countdown timer that prompts the user to input a number of seconds. Subsequently, the program counts down, ticking off each second until it presents a concluding message.
To achieve this, we’ve employed the .sleep() function from the Python time module, introducing one-second intervals for the countdown. The implementation also utilizes creative string formatting techniques to craft the countdown display.
import time
def countdown(user_time):
while user_time >= 0:
mins, secs = divmod(user_time, 60)
timer = '{:02d}:{:02d}'.format(mins, secs)
print(timer, end='\r')
time.sleep(1)
user_time -= 1
print('Lift off!')
if __name__ == '__main__':
user_time = int(input("Enter a time in seconds: "))
countdown(user_time)





Leave a Reply