<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nincy</title>
    <description>The latest articles on Forem by Nincy (@enincy).</description>
    <link>https://forem.com/enincy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3214276%2F9aebb0ec-47d4-4591-9bb1-c32803e7d420.jpeg</url>
      <title>Forem: Nincy</title>
      <link>https://forem.com/enincy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/enincy"/>
    <language>en</language>
    <item>
      <title>My Desktop Was a Mess — So I Wrote a Python Script!!</title>
      <dc:creator>Nincy</dc:creator>
      <pubDate>Wed, 04 Jun 2025 06:08:06 +0000</pubDate>
      <link>https://forem.com/enincy/my-desktop-was-a-mess-so-i-wrote-a-python-script-412d</link>
      <guid>https://forem.com/enincy/my-desktop-was-a-mess-so-i-wrote-a-python-script-412d</guid>
      <description>&lt;p&gt;Hey Devs 👋&lt;/p&gt;

&lt;p&gt;I'm currently learning Python and ones of the  mini-projects I rencently built was a real-life scrip to clean up my messy desktop. Here's what I wanted to do, specifically:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Move all .jpg and .png screenshots from one folder to another.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rename them in a structured way (like 0_filename´.png, 1_filename.jpg, and so forth)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A really great little exercise to practice file manipulation and loops - and to be honest, that is stressful but nice at the same time. &lt;/p&gt;

&lt;p&gt;🧠 &lt;em&gt;&lt;strong&gt;What the Scipt Does&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Here's the full code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pathlib

# Find the path to my Desktop
home = pathlib.Path(r"C:\Users\lopez\OneDrive\Escritorio")
screenshots = home / "screenshots"

# Create screenshots folder if it doesn't exist
if not screenshots.exists():
    screenshots.mkdir()

# Move screenshots
for filepath in home.iterdir():
    if filepath.is_file() and filepath.suffix.lower() in [".jpg", ".png"]:
        destination = screenshots / filepath.name
        print("Moving:", filepath, "to", destination)
        filepath.replace(destination)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;("Escritorio" because my language is Spanish, but if yours is in English would be "Desktop")&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So now, 🔍 &lt;em&gt;&lt;strong&gt;LET'S BREAK IT DOWN&lt;/strong&gt;&lt;/em&gt; 🔍&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Import pathlib&lt;/em&gt;&lt;/strong&gt;: This imports Python’s pathlib module, for when you want to do file paths in a much nicer, object-oriented way. It’s a lot more human-readable than fiddling with os.path.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;screenshots&lt;/em&gt;&lt;/strong&gt;: We set the path to the directory containing my original screenshots. Now, that will surely tell your Python: “Check out this folder!”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;destination.mkdir(exist_ok=True)&lt;/em&gt;&lt;/strong&gt;: Finally, we make a new folder where the images with their new names will place. The exist_ok=True tells Python not to complain if the folder does not exist.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;for index, filepath in enumerate(...)&lt;/em&gt;&lt;/strong&gt;: Enumerating all files in the screenshots folder so that we have an index (0, 1, 2...) to rename files sequentially.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;if filepath.suffix == ".jpg" or filepath.suffix == ".png"&lt;/strong&gt;&lt;/em&gt; : Checks if the file is of type .jpg or .png&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;screenshot = destination.joinpath(...)&lt;/strong&gt;&lt;/em&gt; : Constructs a new path within the destination folder with the file renamed, that is to say, with no white space composite ’’, etc. is changed to ‘_’&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;filepath.replace(screenshot)&lt;/em&gt;&lt;/strong&gt; : The last part moves the file from its original folder to the newly created one with a new name.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🧪 &lt;em&gt;&lt;strong&gt;Output Example&lt;/strong&gt;&lt;/em&gt; 🧪&lt;br&gt;
&lt;em&gt;This is the output when running:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Print result: C:\Users\lopez\OneDrive\Escritorio\renamed_screenshots\0_image1.png&lt;/li&gt;
&lt;li&gt;Print result: C:\Users\lopez\OneDrive\Escritorio\renamed_screenshots\1_screenshot2.jpg
... &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;And just like that, my screenshots are all neatly organized and renamed! &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🤔 &lt;em&gt;&lt;strong&gt;What I Learned&lt;/strong&gt;&lt;/em&gt; 🤔&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to use pathlib for modern path handling.&lt;/li&gt;
&lt;li&gt;How to create directories in Python. &lt;/li&gt;
&lt;li&gt;How to loop through files and rename them on the fly.&lt;/li&gt;
&lt;li&gt;Most importantly, how rewarding it is to write scripts that tackle real-life challenges! &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🚀 &lt;strong&gt;&lt;em&gt;Final Thoughts&lt;/em&gt;&lt;/strong&gt; 🚀&lt;br&gt;
If you're diving into Python, I can't recommend enough that you try building small tools like this. It gives you instant feedback and makes your learning experience feel incredibly practical.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>"Python Hangman: Guess the Word, Learn the Code"</title>
      <dc:creator>Nincy</dc:creator>
      <pubDate>Mon, 02 Jun 2025 09:14:37 +0000</pubDate>
      <link>https://forem.com/enincy/python-hangman-guess-the-word-learn-the-code-52al</link>
      <guid>https://forem.com/enincy/python-hangman-guess-the-word-learn-the-code-52al</guid>
      <description>&lt;p&gt;CLI games are fantastic to solidify your understanding of programming concepts in general. One such activity I have done with Python (to learn the language) was to write a basic (Not so basic after all) Hangman game, even wanted to do it on paper several times XD – a text game in which the player has to guess the word by suggesting letters and is given only a certain number of attempts to do so.&lt;br&gt;
In this article we look at the creation of the game, its design, how its mechanics are implemented, as well as our approach to handling input, and considerations I made for improvements in the future.&lt;/p&gt;

&lt;p&gt;🧩&lt;strong&gt;&lt;em&gt;GAME STRUCTURE&lt;/em&gt;&lt;/strong&gt;🧩&lt;br&gt;
The game was purposefully made an isolated, standalone game without dependencies. Here are the big details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Target word as hardcoded: “universe”.&lt;/li&gt;
&lt;li&gt;State: The state of the game is maintained using lists and sets.&lt;/li&gt;
&lt;li&gt;Attempts limit: 8 Incorrect tries&lt;/li&gt;
&lt;li&gt;Terminal I/O: Prompt about forword search, and updates based on back search.
The structure is designed to be clean and the control flow to be clear, so it's not hard to follow the game's logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🎯&lt;em&gt;&lt;strong&gt;CARE LOGIC&lt;/strong&gt;&lt;/em&gt; 🎯&lt;br&gt;
The main engine of the game is just a loop that keeps on going until the user has guessed the word or run out of turns. Here’s how the game handles the user input and updates its own state.&lt;/p&gt;

&lt;p&gt;1- &lt;strong&gt;&lt;em&gt;See Word State:&lt;/em&gt;&lt;/strong&gt; the word is shown such as unguessed letter are displayed as (*&lt;em&gt;e.g., u _ _ _ _ _ _ e *&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;2- &lt;strong&gt;&lt;em&gt;Input Validation:&lt;/em&gt;&lt;/strong&gt; The user is asked to enter 1 alphabetic character. All other illegal inputs, multiple characters, numbers or punctuations are rejected and prompted with a clear message: (&lt;em&gt;"Invalid input. Please enter a single alphabetic character."&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;3- &lt;strong&gt;&lt;em&gt;Tracking guesses&lt;/em&gt;&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A guessed_letters set prevents repeated inputs.&lt;/li&gt;
&lt;li&gt;If the guess is correct. This is reflected in the word_display position.&lt;/li&gt;
&lt;li&gt;Otherwise, the counter of remaining trials is decreased.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;4- &lt;strong&gt;&lt;em&gt;Victory defeat&lt;/em&gt;&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Winning is recognized if no underscores remain in the display.&lt;/li&gt;
&lt;li&gt;When the player has no more attempts the game ends and the player sees the correct word:  (&lt;em&gt;"\nSorry, you've run out of attempts. The word was:", &lt;strong&gt;word_to_guess&lt;/strong&gt;&lt;/em&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;_&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This concept also encourages positive user interaction and pacing and yet stays completely within terminal output.&lt;br&gt;
_&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔨&lt;strong&gt;&lt;em&gt;DESIGN CONSIDERATIONS&lt;/em&gt;&lt;/strong&gt; 🔨&lt;br&gt;
Having the sets such as, guessed_letters or correct_letters – especially for the above operations of lookups, makes it possible to have lookups performed effectively and keep the logic from being repeated. The list is updated in place, and the display logic can simply reflect a game state.&lt;/p&gt;

&lt;p&gt;Although the game's word is hardcoded now, such this word can change when we decide not to have more copy-paste and we decide to "Ship" the game, as the technical team do the hard work here. But it is an opportunity for growth, as well.&lt;/p&gt;

&lt;p&gt;❌ &lt;em&gt;&lt;strong&gt;LIMITATIONS&lt;/strong&gt;&lt;/em&gt; ❌&lt;br&gt;
This game was a great way to practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validation of the input and cycling of the user.&lt;/li&gt;
&lt;li&gt;The manipulation of simple data structures for state handling.&lt;/li&gt;
&lt;li&gt;That big picture of breaking logic into friendly, maintainable blocks.&lt;/li&gt;
&lt;li&gt;How to keep user experience even between CLI based environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simple though it may be, it is a good example of interactive programming and it shows how simple projects can light the way to broaden programming concepts.&lt;/p&gt;

&lt;p&gt;👣 &lt;em&gt;&lt;strong&gt;NEXT STEPS&lt;/strong&gt;&lt;/em&gt; 👣&lt;br&gt;
Some improvements I might suggest for future versions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Use random. choice() to choose a word from a list or a file with a dictionary.&lt;/li&gt;
&lt;li&gt;  Add ASCII visuals of the hangman as attempts decrease.&lt;/li&gt;
&lt;li&gt;  Add some challenge levels by modifying the word length or the attempts.&lt;/li&gt;
&lt;li&gt;  Add support for whole word guessing and hints:
&lt;em&gt;(this would make the game not just an introduction, but a full-fledged fun interactive CLI application)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 &lt;em&gt;&lt;strong&gt;FINAL THOUGHTS&lt;/strong&gt;&lt;/em&gt; 💡&lt;br&gt;
It’s a little one-trick pony of a game, but it does what it aims to do: provide a playable, interactive game using basic Python data structures. It also establishes the base to work with.&lt;br&gt;
Whether a learning aid, interview showpiece or simply a steppingstone to bigger work, this sort of game demonstrates how straightforward code can still be memorable, enjoyable and illuminating.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;CODE BLOCK&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import string

word_to_guess = "universe"
max_attempts = 8
guessed_letters = set()
correct_letters = set()
word_display = ["_"] * len(word_to_guess)

print("Welcome to Hangman!")
print(f"You have {max_attempts} attempts to guess the word.")
print("The word has", len(word_to_guess), "letters.")

def display_word():
    return " ".join(word_display)

attempts_left = max_attempts
while attempts_left &amp;gt; 0:
    print("\nWord:", display_word())
    print(f"Attempts remaining: {attempts_left}")

    guess = input("Enter a single letter: ").lower()

    if len(guess) != 1 or guess not in string.ascii_lowercase:
        print("Invalid input. Please enter a single alphabetic character.")
        continue

    if guess in guessed_letters:
        print("You've already guessed that letter.")
        continue

    guessed_letters.add(guess)

    if guess in word_to_guess:
        print("Good guess!")
        for i, char in enumerate(word_to_guess):
            if char == guess:
                word_display[i] = guess
                correct_letters.add(guess)
        if "_" not in word_display:
            print("\nCongratulations! You guessed the word:", word_to_guess)
            break
    else:
        print("Wrong guess.")
        attempts_left -= 1

else:
    print("\nSorry, you've run out of attempts. The word was:", word_to_guess)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.seekpng.com%2Fipng%2Fu2w7i1a9w7q8q8r5_the-hangman-logo-hangman-png%2F" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.seekpng.com%2Fipng%2Fu2w7i1a9w7q8q8r5_the-hangman-logo-hangman-png%2F" alt="Image credits" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>python</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
