<?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: Luis Felipe Hernandez Mora</title>
    <description>The latest articles on DEV Community by Luis Felipe Hernandez Mora (@luisfelipehernandezmora).</description>
    <link>https://dev.to/luisfelipehernandezmora</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%2F713930%2F69150514-270f-4217-8942-8bf5ff2a8dde.jpeg</url>
      <title>DEV Community: Luis Felipe Hernandez Mora</title>
      <link>https://dev.to/luisfelipehernandezmora</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/luisfelipehernandezmora"/>
    <language>en</language>
    <item>
      <title>Automation project</title>
      <dc:creator>Luis Felipe Hernandez Mora</dc:creator>
      <pubDate>Sat, 09 Oct 2021 04:09:28 +0000</pubDate>
      <link>https://dev.to/luisfelipehernandezmora/automation-project-3ibk</link>
      <guid>https://dev.to/luisfelipehernandezmora/automation-project-3ibk</guid>
      <description>&lt;p&gt;I am studying Python is a very good place called Coding Nomads, as part of one of my assignments I have to make post about one of my automation homeworks. In this case the goal was to make a program that takes all the given files of a directory (given in the code) and rename the files using a counter; all this using the module pathlib. So this is my code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;pathlib&lt;/span&gt;

&lt;span class="nx"&gt;folder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;pathlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C:/Users/Amma/Desktop/Coding Nomads/python-101-main/13_modules-and-automation/Example for rename&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;folder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;iterdir&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nx"&gt;old_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stem&lt;/span&gt;
    &lt;span class="nx"&gt;old_ext&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;suffix&lt;/span&gt;
    &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;suffix&lt;/span&gt;
    &lt;span class="nx"&gt;new_stem&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is the file {a} and now the format is {c}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;new_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;new_stem&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;old_ext&lt;/span&gt;
    &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pathlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;folder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;new_name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;I do find one error, is when you open one of the files that you will rename, so the program is not able to rename that file and give the next error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;PermissionError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;WinError&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nx"&gt;El&lt;/span&gt; &lt;span class="nx"&gt;proceso&lt;/span&gt; &lt;span class="nx"&gt;no&lt;/span&gt; &lt;span class="nx"&gt;tiene&lt;/span&gt; &lt;span class="nx"&gt;acceso&lt;/span&gt; &lt;span class="nx"&gt;al&lt;/span&gt; &lt;span class="nx"&gt;archivo&lt;/span&gt; &lt;span class="nx"&gt;porque&lt;/span&gt; &lt;span class="nx"&gt;está&lt;/span&gt; &lt;span class="nx"&gt;siendo&lt;/span&gt; &lt;span class="nx"&gt;utilizado&lt;/span&gt; &lt;span class="nx"&gt;por&lt;/span&gt; &lt;span class="nx"&gt;otro&lt;/span&gt; &lt;span class="nx"&gt;proceso&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Users&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Amma&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Desktop&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Coding Nomads&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;python-101-main&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;13_modules-and-automation&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Example for rename&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;This is the file 7 and the format is .docx.docx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Users&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Amma&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Desktop&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Coding Nomads&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;python-101-main&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;13_modules-and-automation&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Example for rename&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;This is the file 23 and now the format is .docx.docx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, effectively I opened and modify the file “This is the file 7 and the format is .docx.docx'”&lt;/p&gt;

&lt;p&gt;The directory there is the one I used as example, but please feel free to try in your pc if you want and post me if you had any problem, also if there is something this code can get better; I will appreciate it. &lt;/p&gt;

</description>
      <category>python</category>
      <category>pathlib</category>
      <category>renamefiles</category>
    </item>
    <item>
      <title>Command line game</title>
      <dc:creator>Luis Felipe Hernandez Mora</dc:creator>
      <pubDate>Sat, 02 Oct 2021 03:40:53 +0000</pubDate>
      <link>https://dev.to/luisfelipehernandezmora/command-line-game-242g</link>
      <guid>https://dev.to/luisfelipehernandezmora/command-line-game-242g</guid>
      <description>&lt;p&gt;The following is a project of an excellent online course I am taking at codingnomads.com. I am a civil engineer who is a beginner in programing and now I am learning Python. I am in the first course, and as part of one of my assignments I had to do a Command-Line game. The basic instructions of the game is:&lt;/p&gt;

&lt;p&gt;• Ask the player for their name.&lt;br&gt;
• Display a message that greets them and introduces them to the game world.&lt;br&gt;
• Present them with a choice between two doors.&lt;br&gt;
• If they choose the left door, they'll see an empty room.&lt;br&gt;
• If they choose the right door, then they encounter a dragon.&lt;br&gt;
• In both cases, they have the option to return to the previous room or interact further.&lt;br&gt;
• When in the seemingly empty room, they can choose to look around. If they do so, they will find a sword. They can choose to take it or leave it.&lt;br&gt;
• When encountering the dragon, they have the choice to fight it.&lt;br&gt;
• If they have the sword from the other room, then they will be able to defeat it and win the game.&lt;br&gt;
• If they don't have the sword, then they will be eaten by the dragon and lose the game.&lt;br&gt;
So first I propose this code, which was functional but susceptible to errors:&lt;br&gt;
name=input("Hello! thanks for playing, what is your name? ")&lt;br&gt;
sword=False&lt;br&gt;
print(f"Hello {name}! Welcome to the game!")&lt;/p&gt;

&lt;p&gt;Win_Game=False&lt;/p&gt;

&lt;p&gt;while Win_Game==False:&lt;br&gt;
    choice=input("Please choose between this 2 doors, Left or Right? ")&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if choice=="Left":
    print(f"Al right {name}! you are in an empty room now! ")
    choice_left=input("You want to look around or go back? Yes(look around) or No(Go back)? ")
    if choice_left=="Yes":
        choice_sword=input("Hey, there is a sword there! Do you want to take it before you go back?? Yes or No? ")
        if choice_sword=="Yes":
            sword=True 
            print("Alright, nothing can stop you now, you have a good sword")
        elif choice_sword=="No":
            print("Alright then! Walk without the sword ")

if choice=="Right":
    print(f"My God {name}, there is a dragon here! ")
    choice_right=input("You want to kill the dragon or go back? Yes or No? ")
    if choice_right=="Yes":
        if sword:
            print(f"Hell Yeah {name}! You kill the dragon! ")
            Win_Game=True
            break
        else:
            print("Oh No! You are eaten by the dragon, you lost the game :/ ")
        break
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;if Win_Game:&lt;br&gt;
    print("Hey you won the game!")&lt;/p&gt;

&lt;p&gt;quit()&lt;/p&gt;

&lt;p&gt;So with the advice of my tutor and friend, he pointed out 3 points I can strength:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; In the section in which I make a user-input of “Yes” or “No”, like when I asked if they want to take the sword, if the user don’t put specifically “Yes” or “No”, but writes something else, like “maybe” or anything else, there is no procedure to proceed, which brings a new concept for me of Sanitation of the input. So far I understand, this mean, that you make sure your program get what is supposed to get in terms of format of the input that user will provide. That’s why he suggest an else clause. &lt;/li&gt;
&lt;li&gt; There is not a real need of the break in the while Win_Game==False, since after completing some condition I also included the Win_Game=True, this will break itself the loop, and there is not a real need for the break in the code. This definitely increase my understanding of loops and help me to make simpler code (that eventually leads to easier and maybe better programing).&lt;/li&gt;
&lt;li&gt; At the end, I am checking, with an IF to display a “You win the game” message, but as the while loop will only be exited once you win the game, there is not a real need for this checking, &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;{&lt;br&gt;
name=input("Hello! thanks for playing, what is your name? ")&lt;br&gt;
sword=False&lt;br&gt;
print(f"Hello {name}! Welcome to the game!")&lt;/p&gt;

&lt;p&gt;Win_Game=False&lt;/p&gt;

&lt;p&gt;while Win_Game==False:&lt;br&gt;
    choice=str(input("Please choose between this 2 doors, left or right? ")).lower()&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if choice=="left":
    print(f"Al right {name}! you are in an empty room now! ")
    choice_left=input("You want to look around or go back? Yes(look around) or No(Go back)? ").lower()
    if choice_left=="yes":
        choice_sword=input("Hey, there is a sword there! Do you want to take it before you go back?? Yes or No? ").lower()
        if choice_sword=="yes":
            sword=True 
            print("Alright, nothing can stop you now, you have a good sword")
        elif choice_sword=="no":
            print("Alright then! Walk without the sword ")
        else:
            print("Well it seems that you are not sure of what to do, you better go back to the 2 doors")
            continue
    elif choice_left=="no":
        continue
    else:
        print("Well it seems that you are not sure of what to do, you better go back to the 2 doors")

if choice=="right":
    print(f"My God {name}, there is a dragon here! ")
    choice_right=input("You want to kill the dragon or go back? Yes or No? ").lower()
    if choice_right=="yes":
        if sword:
            print(f"Hell Yeah {name}! You kill the dragon! ")
            Win_Game=True
            #break
        else:
            print("Oh No! You are eaten by the dragon, you lost the game :/ ")
            quit() #new position to exit the loop and the game
        #break
    elif choice_right=="no":
        print("Alright run back then!")
        continue
    else:
        print("Well it seems that you are not sure of what to do, you better go back to the 2 doors")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;print("Hey you won the game!")&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Making these changes, now the game still works, but can receive answers different than yes or no, and it will not collapse. Thanks to the people that helped me with this small projects of my course, and I am looking forward to keep learning. &lt;/p&gt;

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