<?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>DEV Community: Francesca Panteli</title>
    <description>The latest articles on DEV Community by Francesca Panteli (@fran_panteli).</description>
    <link>https://dev.to/fran_panteli</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%2F3447976%2F133b52f5-bd2d-4941-a5a2-b329cde4ef0a.png</url>
      <title>DEV Community: Francesca Panteli</title>
      <link>https://dev.to/fran_panteli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fran_panteli"/>
    <language>en</language>
    <item>
      <title>How I Built a Screenshot Mover With Python</title>
      <dc:creator>Francesca Panteli</dc:creator>
      <pubDate>Fri, 22 Aug 2025 14:06:57 +0000</pubDate>
      <link>https://dev.to/fran_panteli/how-i-built-a-screenshot-mover-with-python-14i6</link>
      <guid>https://dev.to/fran_panteli/how-i-built-a-screenshot-mover-with-python-14i6</guid>
      <description>&lt;h1&gt;
  
  
  Automating File Organisation With Python: A File Mover Script
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As part of my Python Web Development Career Track with CodingNomads, I wrote a Python script to move screenshots into a new directory in a given directory. This moves .png files from a general directory into a new subdirectory, automating file management.&lt;/p&gt;

&lt;p&gt;This project uses the pathlib module, to implement path manipulation, iteration, conditional logic, and basic filesystem operations with Python.&lt;/p&gt;

&lt;p&gt;This article provides a project walkthrough, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Project requirements&lt;/li&gt;
&lt;li&gt;Details when implementing code&lt;/li&gt;
&lt;li&gt;A walkthrough with explanations&lt;/li&gt;
&lt;li&gt;Lessons learnt&lt;/li&gt;
&lt;li&gt;Potential project improvements &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Project Concept
&lt;/h2&gt;

&lt;p&gt;This script solves the problem of managing mixed file types in a single directory. This is because manually sorting files by their type can be tedious, especially when managing larger volumes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A base directory containing multiple file types (.pdf, .txt, .png)&lt;/li&gt;
&lt;li&gt;A new subdirectory, png_files, is created for storing .png files&lt;/li&gt;
&lt;li&gt;The script iterates through the files in the base directory, only moving .png files&lt;/li&gt;
&lt;li&gt;Other file types remain unmoved&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach uses path manipulation, conditional filtering, and file operations via Python's pathlib module.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Structure
&lt;/h2&gt;

&lt;p&gt;The file tree for this project is below:&lt;/p&gt;

&lt;p&gt;.&lt;br&gt;
├── mover.py&lt;br&gt;
└── moving_files&lt;br&gt;
├── example.pdf&lt;br&gt;
├── example.txt&lt;br&gt;
└── png_files&lt;br&gt;
├── example_one.png&lt;br&gt;
├── example_three.png&lt;br&gt;
└── example_two.png&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;mover.py:&lt;/strong&gt; the main project script&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;moving_files:&lt;/strong&gt; the directory containing the files to be processed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;png_files:&lt;/strong&gt; the destination subdirectory for .png files&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;This project was built using a single Python script. The following sections describe its implementation.&lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;Importing Dependencies&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This uses the &lt;code&gt;pathlib&lt;/code&gt; module to provide an object-oriented interface for filesystem paths. This uses &lt;code&gt;Path&lt;/code&gt; objects for path construction, iteration, and manipulation.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Defining the Target Directory&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;folder_directory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/Users/francescapanteli/Desktop/CodingNomads-python-101/codingnomads/projects/mover&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;folder_directory&lt;/code&gt; specifies the directory of the files to be moved. Using &lt;code&gt;Path&lt;/code&gt; objects for this allows for cross-platform path handling.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Subdirectory Initialisation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;new_folder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;folder_directory&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;png_files&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;new_folder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exist_ok&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This section of the code creates a subdirectory called &lt;code&gt;png_files&lt;/code&gt;, to store the &lt;code&gt;.png&lt;/code&gt; files in the previously specified directory. The parameter &lt;code&gt;exist_ok=True&lt;/code&gt; prevents the generation of an error that shows if this directory already exists. This ensures that the script can be run multiple times without generating the error.&lt;/p&gt;

&lt;p&gt;4.&lt;strong&gt;Iterating and Filtering Files&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;folder_directory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;iterdir&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;suffix&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.png&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;new_file_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new_folder&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_file_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;folder_directory.iterdir()&lt;/code&gt; iterates over all files in the directory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;file.suffix&lt;/code&gt; checks the file extension&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.png&lt;/code&gt; files are moved to the &lt;code&gt;png_files&lt;/code&gt; subdirectory using &lt;code&gt;file.rename(new_file_path)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;This ensures that other file types (&lt;code&gt;.pdf&lt;/code&gt;, &lt;code&gt;.txt&lt;/code&gt;, etc.) remain unmoved&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example Code Implementation
&lt;/h2&gt;

&lt;p&gt;Before running the script, the &lt;code&gt;moving_files&lt;/code&gt; directory contains mixed file types. After executing &lt;code&gt;mover.py&lt;/code&gt;, all .png files are moved into the &lt;code&gt;png_files&lt;/code&gt; directory. This automation removes the need to manually move these files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons Learnt
&lt;/h2&gt;

&lt;p&gt;This project uses the following Python concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pathlib and Path Objects:&lt;/strong&gt; to navigate and manipulate file paths&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Iteration:&lt;/strong&gt; looping over directory contents using &lt;code&gt;iterdir()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conditional Logic:&lt;/strong&gt; selecting files based on their extension&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File Operations:&lt;/strong&gt; moving files by using the &lt;code&gt;rename()&lt;/code&gt; method&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automation:&lt;/strong&gt; applying Python scripts to automate repetitive tasks&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Potential Improvements
&lt;/h2&gt;

&lt;p&gt;The script can be extended in several ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Command-line Arguments:&lt;/strong&gt; using &lt;code&gt;argparse&lt;/code&gt;, to allow dynamic directory and file type input&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling:&lt;/strong&gt; adding checks for missing directories, permission issues, or filename conflicts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logging:&lt;/strong&gt; maintaining a record of moved files&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple File Types:&lt;/strong&gt; extending functionality to organise &lt;code&gt;.pdf&lt;/code&gt;, &lt;code&gt;.txt&lt;/code&gt;, &lt;code&gt;.jpg&lt;/code&gt;, etc&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Source Code
&lt;/h2&gt;

&lt;p&gt;This project is viewable on GitHub, at: &lt;a href="https://github.com/franpanteli/CodingNomads-python-101/blob/main/labs/projects/mover/mover.py" rel="noopener noreferrer"&gt;https://github.com/franpanteli/CodingNomads-python-101/blob/main/labs/projects/mover/mover.py&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>cli</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How I Built a Dungeons and Dragons Game With Python</title>
      <dc:creator>Francesca Panteli</dc:creator>
      <pubDate>Fri, 22 Aug 2025 12:35:28 +0000</pubDate>
      <link>https://dev.to/fran_panteli/test-article-lig</link>
      <guid>https://dev.to/fran_panteli/test-article-lig</guid>
      <description>&lt;p&gt;&lt;strong&gt;Building a Text-Based Dungeons and Dragons Game with Python&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As part of my Python Web Development Career Track with CodingNomads, I built a text-based adventure game, inspired by Dungeons and Dragons. The objective of this project was to invest in my understanding of Python fundamentals, such as user input, conditionals, variables, and control flow.&lt;/p&gt;

&lt;p&gt;This article provides a walkthrough of this project, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Project concept and requirements &lt;/li&gt;
&lt;li&gt;How the project was built&lt;/li&gt;
&lt;li&gt;A walk-through of its code&lt;/li&gt;
&lt;li&gt;Lessons learnt&lt;/li&gt;
&lt;li&gt;Potential improvements to the project &lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Project Concept
&lt;/h2&gt;

&lt;p&gt;This game simulates a basic dungeon exploration scenario, where the player must choose between two doors. Depending on their choice of door, they can encounter a sword, face a dragon, or be defeated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The user enters their name and gets welcomed to the game&lt;/li&gt;
&lt;li&gt;The player chooses a door (“left” or “right”)&lt;/li&gt;
&lt;li&gt;If the player explores and picks up a sword, they have an opportunity to slay the dragon&lt;/li&gt;
&lt;li&gt;If the player encounters the dragon without the sword, they lose the game&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;This program was implemented in a single Python script, run in the CLI. The following sections describe its main components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. User Input and Greeting&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Type your name: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, to the game world!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code in this section:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;input() - for storing and collecting input from the player &lt;/li&gt;
&lt;li&gt;String concatenation, to ensure that the program output is context-specific &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Door Selection&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;door_choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pick between these two doors, left and right: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;door_choice&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;left&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Nothing is behind this door&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;door_choice&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;right&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DRAGON!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This section of the script uses branching logic via if statements to create different user outcomes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Returning or Exploring&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;return_to_previous_door&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Would you like to return to the previous door (you can say yes)? &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;return_to_previous_door&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;no&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DRAGON!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You lose the game, you were defenceless!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This uses nested user interactions, to provide extra options for the user to choose between.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Sword Acquisition&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;return_to_previous_door&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;yes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You encountered a sword!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;pick_up_sword&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pick up sword (you can say yes)? &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This part of the program uses variables, to track whether or not the user has picked up the sword. The status of this tracking will determine if the user wins the game.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Final Encounter&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pick_up_sword&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;yes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;can_fight_dragon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You defeated the dragon!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pick_up_sword&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;no&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DRAGON!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You lose the game, you were defenceless!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Boolean called &lt;code&gt;can_fight_dragon&lt;/code&gt; is True if the sword is encountered and picked up. This is the winning condition of the game, if the user encounters the dragon and this variable is True. &lt;/p&gt;




&lt;h2&gt;
  
  
  Lessons Learnt
&lt;/h2&gt;

&lt;p&gt;This project explored Python fundamentals, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User Input Handling: acquiring user feedback and implementing this via string concatenation &lt;/li&gt;
&lt;li&gt;Conditional Statements: using branching logic with if statements&lt;/li&gt;
&lt;li&gt;Boolean State: using the boolean &lt;code&gt;can_fight_dragon&lt;/code&gt; to track the progress of the game&lt;/li&gt;
&lt;li&gt;Control Flow: building a project with a certain logical sequence of events&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Potential Improvements
&lt;/h2&gt;

&lt;p&gt;The current version of this project is linear. Possible improvements to this include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding multiple rooms to the dungeon and various character narratives &lt;/li&gt;
&lt;li&gt;Introducing a Health Point (HP) system&lt;/li&gt;
&lt;li&gt;Allowing the user to fight the dragon with different combat moves &lt;/li&gt;
&lt;li&gt;Using an inventory system to log the weapons that the user has picked up&lt;/li&gt;
&lt;li&gt;Adding functions to the code, to make it more modular&lt;/li&gt;
&lt;li&gt;Adding loops to the code to make the game replayable, without having to restart it&lt;/li&gt;
&lt;li&gt;Using Flask or Django, to convert the CLI-based game into a full web application&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Source Code
&lt;/h2&gt;

&lt;p&gt;This project is available on GitHub, at: &lt;a href="https://github.com/franpanteli/CodingNomads-python-101/blob/main/labs/projects/dungeons_and_dragon_game.py/dungeons_and_dragon_game.py" rel="noopener noreferrer"&gt;https://github.com/franpanteli/CodingNomads-python-101/blob/main/labs/projects/dungeons_and_dragon_game.py/dungeons_and_dragon_game.py&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building this project provided me with education on Python’s foundational concepts. This program demonstrates how user input, conditional, and state management may be used to create interactive applications. This project could be improved by using web-based interfaces, rather than a CLI. This could secondly be improved by using more complex game mechanics. This would allow more advanced Python concepts to be applied. &lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>cli</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
