├── .gitignore ├── README.md ├── atm.py ├── cows_and_bulls_game.py ├── currency_converter.py ├── dice_rolling_game.py ├── number_guessing_game.py ├── password_generator.py ├── password_strength_checker.py ├── pig_dice_game.py ├── qr_code_generator.py ├── quiz_game.py ├── rock_paper_scissor.py ├── simple_text_editor.py ├── slot_machine.py ├── tic_tac_toe.py ├── todo_list.py ├── word_guessing_game.py └── words.txt /.gitignore: -------------------------------------------------------------------------------- 1 | venv/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python Projects for Beginners 2 | 3 | This repository contains all the code examples and projects from the *Python Projects for Beginners* course. Each project is designed to help you sharpen your problem-solving skills and reinforce your understanding of Python. 4 | 5 | To get started, you can check out the first hour on my YouTube channel or dive even deeper with the complete course on my website. 6 | 7 | YouTube Channel: 8 | https://www.youtube.com/c/programmingwithmosh 9 | 10 | Website: 11 | https://codewithmosh.com 12 | -------------------------------------------------------------------------------- /atm.py: -------------------------------------------------------------------------------- 1 | class ATM: 2 | def __init__(self): 3 | self.balance = 0 4 | 5 | def check_balance(self): 6 | return self.balance 7 | 8 | def deposit(self, amount): 9 | if amount <= 0: 10 | raise ValueError('Deposit amount must be positive.') 11 | 12 | self.balance += amount 13 | 14 | def withdraw(self, amount): 15 | if amount <= 0: 16 | raise ValueError('Withdrawal amount must be positive.') 17 | if amount > self.balance: 18 | raise ValueError('Insufficient funds.') 19 | 20 | self.balance -= amount 21 | 22 | class ATMController: 23 | def __init__(self): 24 | self.atm = ATM() 25 | 26 | def get_number(self, prompt): 27 | while True: 28 | try: 29 | number = float(input(prompt)) 30 | return number 31 | except ValueError: 32 | print('Please enter a valid number.') 33 | 34 | 35 | def display_menu(self): 36 | print('\nWelcome to the ATM!') 37 | print('1. Check Balance') 38 | print('2. Deposit') 39 | print('3. Withdraw') 40 | print('4. Exit') 41 | 42 | def check_balance(self): 43 | balance = self.atm.check_balance() 44 | print(f'Your current balance is: ${balance}') 45 | 46 | def deposit(self): 47 | while True: 48 | try: 49 | amount = self.get_number('Enter the amount to deposit: ') 50 | self.atm.deposit(amount) 51 | print(f'Successfully deposited ${amount}.') 52 | break 53 | except ValueError as error: 54 | print(error) 55 | 56 | def withdraw(self): 57 | while True: 58 | try: 59 | amount = self.get_number('Enter the amount to withdraw: ') 60 | self.atm.withdraw(amount) 61 | print(f'Successfully withdrew ${amount}.') 62 | break 63 | except ValueError as error: 64 | print(error) 65 | 66 | def run(self): 67 | while True: 68 | self.display_menu() 69 | 70 | choice = input('Please choose an option: ') 71 | if choice == '1': 72 | self.check_balance() 73 | elif choice == '2': 74 | self.deposit() 75 | elif choice == '3': 76 | self.withdraw() 77 | elif choice == '4': 78 | print('Thank you for using the ATM.') 79 | break 80 | else: 81 | print('Invalid choice. Please try again.') 82 | 83 | 84 | def main(): 85 | atm = ATMController() 86 | atm.run() 87 | 88 | 89 | if __name__ == '__main__': 90 | main() -------------------------------------------------------------------------------- /cows_and_bulls_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def generate_secret(): 4 | digits = list(range(10)) 5 | random.shuffle(digits) 6 | return ''.join([str(digit) for digit in digits[:4]]) 7 | 8 | 9 | def calculate_cows_and_bulls(secret, guess): 10 | bulls = sum([1 for i in range(4) if guess[i] == secret[i]]) 11 | cows = sum([1 for i in range(4) if guess[i] in secret]) - bulls 12 | 13 | return cows, bulls 14 | 15 | 16 | def main(): 17 | secret = generate_secret() 18 | print('I have generated a 4-digit number with unique digits. Try to guess it!') 19 | 20 | while True: 21 | guess = input('Guess: ') 22 | if len(guess) == 4 and guess.isdigit() and len(set(guess)) == 4: 23 | cows, bulls = calculate_cows_and_bulls(secret, guess) 24 | print(f'{cows} cows, {bulls} bulls') 25 | 26 | if bulls == 4: 27 | print('Congratulations! You guessed the correct number') 28 | break 29 | else: 30 | print('Invalid guess. Please enter a 4-digit number with unique digits.') 31 | 32 | 33 | if __name__ == '__main__': 34 | main() -------------------------------------------------------------------------------- /currency_converter.py: -------------------------------------------------------------------------------- 1 | def get_amount(): 2 | while True: 3 | try: 4 | amount = float(input('Enter the amount: ')) 5 | if amount <= 0: 6 | raise ValueError() 7 | return amount 8 | except ValueError: 9 | print('Invalid amount') 10 | 11 | def get_currency(label): 12 | currencies = ('USD', 'EUR', 'CAD') 13 | while True: 14 | currency = input(f'{label} currency (USD/EUR/CAD): ').upper() 15 | if currency not in currencies: 16 | print('Invalid currency') 17 | else: 18 | return currency 19 | 20 | 21 | def convert(amount, source_currency, target_currency): 22 | exchange_rates = { 23 | 'USD': { 'EUR': 0.85, 'CAD': 1.25 }, 24 | 'EUR': { 'USD': 1.18, 'CAD': 1.47 }, 25 | 'CAD': { 'USD': 0.80, 'EUR': 0.68 }, 26 | } 27 | 28 | if source_currency == target_currency: 29 | return amount 30 | 31 | return amount * exchange_rates[source_currency][target_currency] 32 | 33 | def main(): 34 | amount = get_amount() 35 | source_currency = get_currency('Source') 36 | target_currency = get_currency('Target') 37 | converted_amount = convert(amount, source_currency, target_currency) 38 | print(f'{amount} {source_currency} is equal to {converted_amount:.2f}') 39 | 40 | 41 | if __name__ == "__main__": 42 | main() -------------------------------------------------------------------------------- /dice_rolling_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | while True: 4 | choice = input('Roll the dice? (y/n): ').lower() 5 | if choice == 'y': 6 | die1 = random.randint(1, 6) 7 | die2 = random.randint(1, 6) 8 | print(f'({die1}, {die2})') 9 | elif choice == 'n': 10 | print('Thanks for playing!') 11 | break 12 | else: 13 | print('Invalid choice!') -------------------------------------------------------------------------------- /number_guessing_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | number_to_guess = random.randint(1, 100) 4 | 5 | while True: 6 | try: 7 | guess = int(input('Guess the number between 1 and 100: ')) 8 | 9 | if guess < number_to_guess: 10 | print('Too low!') 11 | elif guess > number_to_guess: 12 | print('Too high!') 13 | else: 14 | print('Congratulations! You guessed the number.') 15 | break 16 | except ValueError: 17 | print('Please enter a valid number') 18 | 19 | -------------------------------------------------------------------------------- /password_generator.py: -------------------------------------------------------------------------------- 1 | import string 2 | import random 3 | 4 | def generate_password(length, include_uppercase, include_numbers, include_special): 5 | if length < (include_uppercase + include_numbers + include_special): 6 | raise ValueError('Password length is too short for the specified criteria.') 7 | 8 | password = '' 9 | 10 | if include_uppercase: 11 | password += random.choice(string.ascii_uppercase) 12 | if include_numbers: 13 | password += random.choice(string.digits) 14 | if include_special: 15 | password += random.choice(string.punctuation) 16 | 17 | # Fill the remaining length with any allowed characters 18 | characters = string.ascii_lowercase 19 | if include_uppercase: 20 | characters += string.ascii_uppercase 21 | if include_numbers: 22 | characters += string.digits 23 | if include_special: 24 | characters += string.punctuation 25 | 26 | for _ in range(length - len(password)): 27 | password += random.choice(characters) 28 | 29 | password_list = list(password) 30 | random.shuffle(password_list) 31 | return ''.join(password_list) 32 | 33 | 34 | def main(): 35 | length = int(input('Enter password length: ')) 36 | include_uppercase = input('Include uppercase letters? (y/n): ').lower() == 'y' 37 | include_numbers = input('Include numbers? (y/n): ').lower() == 'y' 38 | include_special = input('Include special characters? (y/n): ').lower() == 'y' 39 | try: 40 | password = generate_password(length, include_uppercase, include_numbers, include_special) 41 | print(password) 42 | except ValueError as e: 43 | print(e) 44 | 45 | 46 | if __name__ == '__main__': 47 | main() -------------------------------------------------------------------------------- /password_strength_checker.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def check_password_strength(password): 4 | strength = 0 5 | 6 | if len(password) >= 8: 7 | strength += 1 8 | if re.search('[a-z]', password): 9 | strength += 1 10 | if re.search('[A-Z]', password): 11 | strength += 1 12 | if re.search('[0-9]', password): 13 | strength += 1 14 | if re.search('[@#$%+=!]', password): 15 | strength += 1 16 | 17 | return strength 18 | 19 | 20 | def main(): 21 | password = input('Enter a password: ') 22 | strength = check_password_strength(password) 23 | 24 | if strength == 5: 25 | print('Password strength: Very Strong') 26 | elif strength == 4: 27 | print('Password strength: Strong') 28 | elif strength == 3: 29 | print('Password strength: Medium') 30 | elif strength == 2: 31 | print('Password strength: Weak') 32 | else: 33 | print('Password strength: Very Weak') 34 | 35 | 36 | 37 | 38 | if __name__ == '__main__': 39 | main() -------------------------------------------------------------------------------- /pig_dice_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def roll_die(): 4 | return random.randint(1, 6) 5 | 6 | def play_turn(player_name): 7 | turn_score = 0 8 | 9 | print(f"\n{player_name}'s turn") 10 | 11 | while True: 12 | roll = roll_die() 13 | print(f'You rolled a {roll}') 14 | 15 | if roll == 1: 16 | return 0 17 | 18 | turn_score += roll 19 | choice = input('Roll again? (y/n): ').lower() 20 | if choice != 'y': 21 | return turn_score 22 | 23 | 24 | def main(): 25 | scores = [0, 0] 26 | current_player = 0 27 | 28 | while True: 29 | player_name = f'Player {current_player + 1}' 30 | turn_score = play_turn(player_name) 31 | scores[current_player] += turn_score 32 | 33 | print(f'\nYou scored {turn_score} points this turn.') 34 | print(f'Current scores: Player 1: {scores[0]}, Player 2: {scores[1]}') 35 | 36 | if scores[current_player] >= 100: 37 | print(f'{player_name} wins!') 38 | break 39 | 40 | current_player = 1 if current_player == 0 else 0 41 | 42 | if __name__ == '__main__': 43 | main() -------------------------------------------------------------------------------- /qr_code_generator.py: -------------------------------------------------------------------------------- 1 | import qrcode 2 | 3 | data = input('Enter the text or URL: ').strip() 4 | filename = input('Enter the filename: ').strip() 5 | qr = qrcode.QRCode(box_size=10, border=4) 6 | qr.add_data(data) 7 | image = qr.make_image(fill_color='black', back_color='white') 8 | image.save(filename) 9 | print(f'QR code saved as {filename}') -------------------------------------------------------------------------------- /quiz_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | from termcolor import cprint 3 | 4 | QUESTION = 'question' 5 | OPTIONS = 'options' 6 | ANSWER = 'answer' 7 | 8 | def ask_question(index, question, options): 9 | print(f'Question {index}: {question}') 10 | for option in options: 11 | print(option) 12 | 13 | return input('Your answer: ').upper().strip() 14 | 15 | def run_quiz(quiz): 16 | random.shuffle(quiz) 17 | 18 | score = 0 19 | 20 | for index, item in enumerate(quiz, 1): 21 | answer = ask_question(index, item[QUESTION], item[OPTIONS]) 22 | 23 | if answer == item[ANSWER]: 24 | cprint('Correct!', 'green') 25 | score += 1 26 | else: 27 | cprint(f'Wrong! The correct answer is {item[ANSWER]}', 'red') 28 | 29 | print() 30 | 31 | print(f'Quiz over! Your final score is {score} out of {len(quiz)}') 32 | 33 | 34 | def main(): 35 | quiz = [ 36 | { 37 | QUESTION: 'What is the capital of France?', 38 | OPTIONS: ['A. Berlin', 'B. Madrid', 'C. Paris', 'D. Rome'], 39 | ANSWER: 'C' 40 | }, 41 | { 42 | QUESTION: 'Which planet is known as the red planet?', 43 | OPTIONS: ['A. Earth', 'B. Mars', 'C. Jupiter', 'D. Saturn'], 44 | ANSWER: 'B' 45 | }, 46 | { 47 | QUESTION: 'What is the largest ocean on Earth?', 48 | OPTIONS: ['A. Atlantic', 'B. Indian', 'C. Arctic', 'D. Pacific'], 49 | ANSWER: 'D' 50 | } 51 | ] 52 | run_quiz(quiz) 53 | 54 | if __name__ == '__main__': 55 | main() -------------------------------------------------------------------------------- /rock_paper_scissor.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | ROCK = 'r' 4 | SCISSORS = 's' 5 | PAPER = 'p' 6 | emojis = { ROCK: '🪨', SCISSORS: '✂️', PAPER: '📃' } 7 | choices = tuple(emojis.keys()) 8 | 9 | def get_user_choice(): 10 | while True: 11 | user_choice = input('Rock, paper, or scissors? (r/p/s): ').lower() 12 | if user_choice in choices: 13 | return user_choice 14 | else: 15 | print('Invalid choice!') 16 | 17 | def display_choices(user_choice, computer_choice): 18 | print(f'You chose {emojis[user_choice]}') 19 | print(f'Computer chose {emojis[computer_choice]}') 20 | 21 | 22 | def determine_winner(user_choice, computer_choice): 23 | if user_choice == computer_choice: 24 | print('Tie!') 25 | elif ( 26 | (user_choice == ROCK and computer_choice == SCISSORS) or 27 | (user_choice == SCISSORS and computer_choice == PAPER) or 28 | (user_choice == PAPER and computer_choice == ROCK)): 29 | print('You win') 30 | else: 31 | print('You lose') 32 | 33 | def play_game(): 34 | while True: 35 | user_choice = get_user_choice() 36 | 37 | computer_choice = random.choice(choices) 38 | 39 | display_choices(user_choice, computer_choice) 40 | 41 | determine_winner(user_choice, computer_choice) 42 | 43 | should_continue = input('Continue? (y/n): ').lower() 44 | if should_continue == 'n': 45 | break 46 | 47 | play_game() -------------------------------------------------------------------------------- /simple_text_editor.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def read_file(filename): 4 | with open(filename, 'r') as file: 5 | return file.read() 6 | 7 | def write_file(filename, content): 8 | with open(filename, 'w') as file: 9 | file.write(content) 10 | 11 | 12 | def get_user_input(): 13 | print('\nEnter your text (type SAVE on a new line to save and exist):') 14 | 15 | lines = [] 16 | while True: 17 | line = input() 18 | if line == 'SAVE': 19 | break 20 | lines.append(line) 21 | 22 | return '\n'.join(lines) 23 | 24 | def main(): 25 | filename = input('Enter the filename to open or create: ').strip() 26 | try: 27 | if os.path.exists(filename): 28 | print(read_file(filename)) 29 | else: 30 | write_file(filename, '') 31 | 32 | content = get_user_input() 33 | write_file(filename, content) 34 | print(f'{filename} saved.') 35 | except OSError: 36 | print(f'{filename} could not be opened.') 37 | 38 | if __name__ == '__main__': 39 | main() -------------------------------------------------------------------------------- /slot_machine.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def get_starting_balance(): 4 | while True: 5 | try: 6 | balance = int(input('Enter your starting balance: $')) 7 | if balance <= 0: 8 | print('Balance must be a positive number.') 9 | else: 10 | return balance 11 | except ValueError: 12 | print('Please enter a valid number.') 13 | 14 | 15 | def get_bet_amount(balance): 16 | while True: 17 | try: 18 | bet = int(input('Enter your bet amount: $')) 19 | if bet > balance or bet <= 0: 20 | print(f'Invalid bet amount. You can bet between $1 and ${balance}.') 21 | else: 22 | return bet 23 | except ValueError: 24 | print('Please enter a valid number for the bet amount.') 25 | 26 | 27 | def spin_reels(): 28 | symbols = ['🍒', '🍋', '🔔', '⭐️', '🍉'] 29 | return [random.choice(symbols) for _ in range(3)] 30 | 31 | 32 | def display_reels(reels): 33 | print(f'{reels[0]} | {reels[1]} | {reels[2]}') 34 | 35 | 36 | def calculate_payout(reels, bet): 37 | if reels[0] == reels[1] == reels[2]: 38 | return bet * 10 39 | if reels[0] == reels[1] or reels[0] == reels[2] or reels[1] == reels[2]: 40 | return bet * 2 41 | return 0 42 | 43 | 44 | def main(): 45 | balance = get_starting_balance() 46 | 47 | print('\nWelcome to the Slot Machine Game!') 48 | print(f'You start with a balance of ${balance}.') 49 | 50 | while balance > 0: 51 | print(f'\nCurrent balance: ${balance}') 52 | 53 | bet = get_bet_amount(balance) 54 | reels = spin_reels() 55 | display_reels(reels) 56 | payout = calculate_payout(reels, bet) 57 | 58 | if payout > 0: 59 | print(f'You won ${payout}!') 60 | else: 61 | print('You lost!') 62 | 63 | balance += payout - bet 64 | if balance <= 0: 65 | print('You are out of money! Game over.') 66 | break 67 | 68 | play_again = input('Do you want to play again? (y/n): ').lower() 69 | if play_again != 'y': 70 | print(f'You walk away with ${balance}.') 71 | break 72 | 73 | 74 | if __name__ == '__main__': 75 | main() -------------------------------------------------------------------------------- /tic_tac_toe.py: -------------------------------------------------------------------------------- 1 | from termcolor import colored 2 | 3 | X = 'X' 4 | O = 'O' 5 | 6 | board = [ 7 | [' ', ' ', ' '], 8 | [' ', ' ', ' '], 9 | [' ', ' ', ' '] 10 | ] 11 | 12 | def cell(mark): 13 | color = 'red' if mark == X else 'green' 14 | return colored(mark, color) 15 | 16 | 17 | def print_board(board): 18 | line = '---+---+---' 19 | print(line) 20 | for row in board: 21 | print(f' {cell(row[0])} | {cell(row[1])} | {cell(row[2])}') 22 | print(line) 23 | 24 | 25 | def check_winner(board): 26 | # Check rows 27 | for row in board: # [' ', ' ', ' '] 28 | if row[0] == row[1] == row[2] != ' ': 29 | return True 30 | 31 | # Check columns 32 | for column in range(3): 33 | if board[0][column] == board[1][column] == board[2][column] != ' ': 34 | return True 35 | 36 | # Check diagonals 37 | if board[0][0] == board[1][1] == board[2][2] != ' ' or \ 38 | board[0][2] == board[1][1] == board[2][0] != ' ': 39 | return True 40 | 41 | return False 42 | 43 | 44 | def is_full(board): 45 | for row in board: 46 | if ' ' in row: 47 | return False 48 | 49 | return True 50 | 51 | 52 | def get_position(prompt): 53 | while True: 54 | try: 55 | position = int(input(prompt)) 56 | if position < 0 or position > 2: 57 | raise ValueError 58 | return position 59 | except ValueError: 60 | print('Invalid input!') 61 | 62 | 63 | def get_move(current_player): 64 | print(f"Player {current_player}'s turn") 65 | while True: 66 | row = get_position('Enter row (0-2): ') 67 | column = get_position('Enter column (0-2): ') 68 | 69 | if board[row][column] == ' ': 70 | board[row][column] = current_player 71 | break 72 | 73 | print('This spot is already taken') 74 | 75 | 76 | def main(): 77 | print_board(board) 78 | 79 | current_player = X 80 | 81 | while True: 82 | get_move(current_player) 83 | 84 | print_board(board) 85 | 86 | if check_winner(board): 87 | print(f'Player {current_player} wins!') 88 | break 89 | 90 | if is_full(board): 91 | print(f'Board is full') 92 | break 93 | 94 | current_player = O if current_player == X else X 95 | 96 | 97 | if __name__ == '__main__': 98 | main() 99 | -------------------------------------------------------------------------------- /todo_list.py: -------------------------------------------------------------------------------- 1 | def print_menu(): 2 | print('\nTodo List Menu:') 3 | print('1. View Tasks') 4 | print('2. Add a Task') 5 | print('3. Remove a Task') 6 | print('4. Exit') 7 | 8 | 9 | def get_choice(): 10 | while True: 11 | choice = input('Enter your choice: ') 12 | valid_choices = ('1', '2', '3', '4') 13 | if choice not in valid_choices: 14 | print('Invalid choice') 15 | continue 16 | else: 17 | return choice 18 | 19 | 20 | def display_tasks(tasks): 21 | if not tasks: 22 | print('No tasks in the list.') 23 | return 24 | 25 | for index, task in enumerate(tasks, start=1): 26 | print(f'{index}. {task}') 27 | 28 | 29 | def add_task(tasks): 30 | while True: 31 | task = input('Enter a new task: ').strip() 32 | if len(task) != 0: 33 | tasks.append(task) 34 | break 35 | else: 36 | print('Invalid task!') 37 | 38 | 39 | def remove_task(tasks): 40 | display_tasks(tasks) 41 | 42 | while True: 43 | try: 44 | task_number = int(input('Enter the task number: ')) 45 | if 1 <= task_number <= len(tasks): 46 | tasks.pop(task_number - 1) 47 | break 48 | else: 49 | raise ValueError 50 | except ValueError: 51 | print('Invalid task number') 52 | 53 | def main(): 54 | tasks = [] 55 | 56 | while True: 57 | print_menu() 58 | 59 | choice = get_choice() 60 | 61 | if choice == '1': 62 | display_tasks(tasks) 63 | elif choice == '2': 64 | add_task(tasks) 65 | elif choice == '3': 66 | remove_task(tasks) 67 | else: 68 | break 69 | 70 | 71 | if __name__ == '__main__': 72 | main() 73 | 74 | -------------------------------------------------------------------------------- /word_guessing_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | import re 3 | 4 | def read_words(): 5 | try: 6 | with open('words.txt', 'r') as file: 7 | words = file.read().splitlines() 8 | return words 9 | except FileNotFoundError: 10 | print('words.txt does not exist.') 11 | return [] 12 | 13 | def display_word(secret_word, guessed_letters): 14 | word_to_display = '' 15 | 16 | for letter in secret_word: 17 | if letter in guessed_letters: 18 | word_to_display += letter 19 | else: 20 | word_to_display += '_' 21 | 22 | print(word_to_display) 23 | 24 | 25 | def get_guess(guessed_letters): 26 | while True: 27 | guess = input('Enter a letter: ').lower() 28 | if len(guess) != 1: 29 | print('Enter only one letter.') 30 | elif not re.search('[a-z]', guess): 31 | print('Enter only letters from a to z.') 32 | elif guess in guessed_letters: 33 | print('You already guessed that letter.') 34 | else: 35 | return guess 36 | 37 | 38 | def is_word_guessed(secret_word, guessed_letters): 39 | for letter in secret_word: 40 | if letter not in guessed_letters: 41 | return False 42 | return True 43 | 44 | 45 | def main(): 46 | words = read_words() 47 | if not words: 48 | print('No words loaded.') 49 | return 50 | secret_word = random.choice(words) 51 | print(secret_word) 52 | 53 | attempts = 6 54 | guessed_letters = [] 55 | while attempts > 0: 56 | display_word(secret_word, guessed_letters) 57 | 58 | guess = get_guess(guessed_letters) 59 | guessed_letters.append(guess) 60 | 61 | if guess in secret_word: 62 | print('Good guess') 63 | if is_word_guessed(secret_word, guessed_letters): 64 | print('Congratulations! You guessed the word') 65 | break 66 | else: 67 | print('Wrong guess') 68 | attempts -= 1 69 | if attempts == 0: 70 | print(f'Game over! The word was {secret_word}') 71 | 72 | 73 | if __name__ == '__main__': 74 | main() -------------------------------------------------------------------------------- /words.txt: -------------------------------------------------------------------------------- 1 | elephant 2 | giraffe 3 | python 4 | jazz 5 | astronaut --------------------------------------------------------------------------------