<?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: Tehreem Fatima</title>
    <description>The latest articles on DEV Community by Tehreem Fatima (@tehreemfatimadev).</description>
    <link>https://dev.to/tehreemfatimadev</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4106128%2F52db792f-a02f-474d-bae2-ed1e3acae3db.png</url>
      <title>DEV Community: Tehreem Fatima</title>
      <link>https://dev.to/tehreemfatimadev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tehreemfatimadev"/>
    <language>en</language>
    <item>
      <title>My Python Learning Journey: Refactoring My Hangman Game from v1.0 to v2.0</title>
      <dc:creator>Tehreem Fatima</dc:creator>
      <pubDate>Wed, 02 Sep 2026 12:14:29 +0000</pubDate>
      <link>https://dev.to/tehreemfatimadev/my-python-learning-journey-refactoring-my-hangman-game-from-v10-to-v20-4kg0</link>
      <guid>https://dev.to/tehreemfatimadev/my-python-learning-journey-refactoring-my-hangman-game-from-v10-to-v20-4kg0</guid>
      <description>&lt;p&gt;This is the first post in my Python learning journey, where I document what I'm learning, what I'm building, the mistakes I make, and how my code improves over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Little About Me
&lt;/h2&gt;

&lt;p&gt;I'm currently studying Biomedical Engineering Technology, and I've been learning Python alongside my studies because I want to develop strong programming skills and build practical projects during my degree.&lt;/p&gt;

&lt;p&gt;I'm still a beginner. I haven't been programming for years, and I'm not trying to present myself as an experienced developer. My goal is much simpler:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn → Build → Make mistakes → Improve → Repeat.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of only completing tutorials, I've been trying to build small projects to actually apply what I learn. So far, I've worked with variables, conditionals, loops, lists, strings, dictionaries, functions, randomization, and sets.&lt;/p&gt;

&lt;p&gt;One of my first real projects was a simple Hangman game. And then I decided to refactor it.&lt;/p&gt;




&lt;h2&gt;
  
  
  My Hangman Game — v1.0
&lt;/h2&gt;

&lt;p&gt;My first version was written mostly as one continuous program.&lt;/p&gt;

&lt;p&gt;It worked. I could:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Randomly select a word&lt;/li&gt;
&lt;li&gt;Display blanks for the letters&lt;/li&gt;
&lt;li&gt;Allow the player to guess letters&lt;/li&gt;
&lt;li&gt;Track lives&lt;/li&gt;
&lt;li&gt;Display Hangman stages&lt;/li&gt;
&lt;li&gt;Reveal correctly guessed letters&lt;/li&gt;
&lt;li&gt;Determine whether the player won or lost&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At this stage, my main focus was simply getting the program to work. And honestly, that's an important stage when you're learning. I wasn't thinking deeply about software architecture. I was thinking:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Can I make this work?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The answer was yes. But once I looked at the program again, I started noticing something: the code was becoming difficult to manage.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem With My First Version
&lt;/h2&gt;

&lt;p&gt;As I added more functionality, the program became longer and harder to reason about. Different responsibilities were mixed together:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choosing a word&lt;/li&gt;
&lt;li&gt;Getting user input&lt;/li&gt;
&lt;li&gt;Validating input&lt;/li&gt;
&lt;li&gt;Updating the hidden word&lt;/li&gt;
&lt;li&gt;Tracking lives&lt;/li&gt;
&lt;li&gt;Checking whether the player won&lt;/li&gt;
&lt;li&gt;Displaying messages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything was happening in the main game loop. This worked for a small project, but I started asking myself:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"What if I want to change one particular part of the game?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example, what if I wanted to improve input validation? I would have to dig through the larger program to find that logic.&lt;/p&gt;

&lt;p&gt;That's when I realized: &lt;strong&gt;making a program work and structuring a program well are two different things.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So I decided to refactor it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Refactoring Hangman — v2.0
&lt;/h2&gt;

&lt;p&gt;For version 2.0, my main goal was to break the program into smaller functions.&lt;/p&gt;

&lt;p&gt;Instead of one large block of code responsible for everything, I separated different responsibilities:&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;def&lt;/span&gt; &lt;span class="nf"&gt;generating_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words_list&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Selects a random word
&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generating_blanks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;choosen_word&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Creates blank display
&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;getting_input&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# Gets player input
&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;input_validation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;guess_letter&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Validates input
&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;replacing_blanks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;choosen_word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;guess_letter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Updates word with correct guesses
&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;game_win_lose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;choosen_word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;remaining_lives&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;guess_letter&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Checks win/lose conditions
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This made the structure much easier to understand. Instead of one large program, I could look at individual pieces and understand what each one was supposed to do.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Input Validation
&lt;/h3&gt;

&lt;p&gt;Previously, the program could receive input like "hello" when it should only accept a single letter. So I added validation to ensure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Exactly one character&lt;/li&gt;
&lt;li&gt;An alphabetic character&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This was a small addition, but it taught me something important: &lt;strong&gt;user input cannot always be trusted to be valid.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Preventing Duplicate Guesses
&lt;/h3&gt;

&lt;p&gt;I added tracking for previously guessed letters using a Python set:&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;guessed_letters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&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;guess_letter&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;guessed_letters&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 already guessed that letter!&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 was a good practical example of learning a data structure and actually using it in a real project, rather than just doing exercises.&lt;/p&gt;

&lt;h3&gt;
  
  
  Breaking the Game Into Responsibilities
&lt;/h3&gt;

&lt;p&gt;My v2.0 structure now looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;main()
  ↓
play_game()
  ├── generating_word()
  ├── generating_blanks()
  ├── getting_input()
  ├── input_validation()
  ├── replacing_blanks()
  └── game_win_lose()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one of the biggest things I learned from this project. A function shouldn't just exist because "functions are good." It should have a clear responsibility.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Learned From the Refactoring
&lt;/h2&gt;

&lt;p&gt;The biggest lesson wasn't about syntax. It was about &lt;strong&gt;thinking differently about code&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When I first started programming, I mostly focused on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Does my code work?"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now I'm slowly learning to ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Is my code organized?"&lt;/li&gt;
&lt;li&gt;"Can I understand it later?"&lt;/li&gt;
&lt;li&gt;"Can I change one part without breaking everything?"&lt;/li&gt;
&lt;li&gt;"Does each function have a clear purpose?"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I definitely still have a lot to learn, but I think this project was an important step in that direction.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Still Need to Improve
&lt;/h2&gt;

&lt;p&gt;My Hangman v2.0 isn't perfect. There are still things I can improve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Being more careful about when to validate input versus when to store it&lt;/li&gt;
&lt;li&gt;Removing unnecessary return values&lt;/li&gt;
&lt;li&gt;Better error handling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are small things, but that's exactly why I'm documenting them. &lt;strong&gt;I don't want to only show the final version and pretend I knew everything from the beginning.&lt;/strong&gt; The mistakes are part of the learning process.&lt;/p&gt;




&lt;h2&gt;
  
  
  v1.0 → v2.0: The Progression
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Main Focus&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;v1.0&lt;/td&gt;
&lt;td&gt;Make the game work&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;v2.0&lt;/td&gt;
&lt;td&gt;Improve structure and reliability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Future&lt;/td&gt;
&lt;td&gt;Further improvements as I learn&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;v1.0 taught me how to build the game.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;v2.0 taught me how to think about improving the code.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And I think that difference is important.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Biggest Takeaway
&lt;/h2&gt;

&lt;p&gt;If I had to summarize what this project taught me in one sentence, it would be this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The most important part of learning to code isn't writing code that works—it's writing code that you (and others) can understand, maintain, and improve.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This shift in thinking will probably make more of a difference in my programming journey than any specific syntax I've learned.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;I'm continuing my Python journey by building more projects rather than only following tutorials. My goal isn't to rush through Python topics—it's to understand concepts well enough that I can approach new problems with confidence.&lt;/p&gt;

&lt;p&gt;There will probably be plenty of bugs, bad code, rewrites, and moments where I wonder why something isn't working. But that's part of learning.&lt;/p&gt;

&lt;p&gt;I'll be documenting this journey here.&lt;/p&gt;

&lt;p&gt;This is only the beginning.&lt;/p&gt;




&lt;h2&gt;
  
  
  Let's Connect
&lt;/h2&gt;

&lt;p&gt;If you're also learning to code, I'd love to hear about your journey! What projects are you building? What mistakes are you making? Drop a comment below—I promise I'm making plenty of my own.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Links:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/tehreem-fatima-dev/hangman_game" rel="noopener noreferrer"&gt;https://github.com/tehreem-fatima-dev/hangman_game&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.udemy.com/course/100-days-of-code/" rel="noopener noreferrer"&gt;Day 7 of 100 Days of Code by Dr. Angela Yu&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




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