Day 113 of #365DaysOfCode: App Testing

Day 113 of #365DaysOfCode & Day 13 of #100DaysOfPython: I've completed building my app! But the journey doesn't stop here. The next stage is testing - an equally critical part of the development process.

When building an app, the testing phase ensures everything works as it should, from user experience to data management. During testing, you aim to find any bugs, errors, or inconsistencies and then fix them. This stage is crucial for the success of any app.

In parallel with my app development, my Python journey is also in full swing. I've recently created a few small projects including a Hangman game, Caesar Cipher, and a prime number checker.

The Hangman game was particularly fun to code! Let's take a closer look at how it works:

import random
from hangman_words import word_list
chosen_word = random.choice(word_list)
word_length = len(chosen_word)

display = []
for _ in range(word_length):
    display += "_"

This first part of the code imports the list of words that could be used in the game, selects a random word from the list, and then creates a placeholder display for the chosen word using underscores (_).

while not end_of_game:
    guess = input("Guess a letter: ").lower()
    for position in range(word_length):
        letter = chosen_word[position]
        if letter == guess:
            display[position] = letter

The game is played in a loop until the game ends. The user inputs a guess for a letter, and if that letter is in the chosen word, the corresponding underscore in the display is replaced by that letter.

The code for the prime number checker is a bit simpler but also quite exciting:

def prime_checker(number):
    flag = False
    if number > 1:
        for i in range (2, number):
            if number % i == 0:
                flag = True
                break
    if flag:
        print("It's not a prime number.")
    else:
        print("It's a prime number.")

The prime_checker function takes a number as input and checks if it's a prime number. It does this by trying to divide the number by all the numbers preceding it. If the number can be divided by any other number than 1 and itself, it's not a prime number. If not, then it's a prime number!

In the coming week!, I plan to learn more intermediate concepts like Object-Oriented Programming (OOP) in Python. Stay tuned for more updates on my coding journey!