Blog

Welcome to Unleash the Python

I’m passionate about Python! I stumbled upon Python a few years ago quite by accident.

Discovering Python was a game changer, I instantly fell head over heels in love with the language!

So what is so great about Python?

Python is a very powerful multipurpose programming language, yet it is very easy to learn. It is open source and widely used. Python has a massive community and support base meaning any problems you encounter have most likely already been solved by someone else.

What is Python used for?

Python is used for everything from System administration and Data Analysis to Artificial Intelligence. From building websites to Database development. Python is used extensively in Finance, Game and GUI development and everything in between.

Companies such as Google, Quora, and Yahoo use Python. It has been used by NASA and The New York Stock Exchange. The vast popularity and diverse uses for Python means it’s programming skills are in high demand.

But I don’t want to be a full time programmer..

You don’t have to be a professional programmer to benefit from python. You can start utilizing Python to solve everyday problems almost immediately.

The practical skills you learn can help you automate a lot of your daily tasks.

Python can search huge documents and parse particular information. For example, suppose your job required you to parse all phone numbers or email address from a document and put it in a spread sheet. Instead of doing this by had you could write a quick program to do it. This will free you up from the routine mind-numbing work.

This is just one of the many examples of how Python can help you in your daily life, even if you have no intention of ever becoming a full-time computer programmer.

At unleashthepython.com we are in the process of building up our information base and resources. Our goal is to eventually be the first port of call for anyone interested in learning the Python programming language. 

 

.

Rock Paper Scissors Python..

rock

Rock Paper Scissors is a decision based game and so can easily be replicated as a computer program.

As usual you can write this program in any text editor. I wrote mine in Notepad++

You can name it what ever you want as long as you save it with the .py extension.  I named my file rock.py

You can then run if from the console or by double clicking on the file itself.

You will see \n used throughout the program. This is an instruction to the program to start on a new line. the n will not show up when your program runs.

Now to the program. Being decision based, the if statement playing a starring role. The while loop is used to keep the program running until we decide to close it.

Rock Paper Scissors is a two-person game. We therefore need to create a variable to store the name of each of the the two players. In another post we will look at playing against the computer. For now though we will keep it as a two player game and assign two variables,  one for each player. This is done via an input statement;

 name_one = input(“Please enter name of Player 1 “)

name_two = input(“Please enter name of Player 2 “)

Now we need to ensure the game keeps running until the user decides to close it. For this we use a while loop. We first create an arbitrary variable; var (it can be called anything) and assign it to an arbitrary number; in this case 1 (any number will do).

We use this opportunity to give instructions to the user using a print statement.

var = 1

 print(“Control + C to end at any time… “)

The while loop is designed to keep running while var is equal to 1. In other words, the loop stays open because it’s condition is valid.

while var == 1:

We now create a variable to store the choice of the two players. We give each player a choice of rock paper or scissors. The player will be instructed to pick a number from 1 to 3 to denote their choice. The choice is stored in the respective variables.

player_one = input(“Hi ” + name_one + ”  enter:\n\n 1 for Rock\n 2 for Paper\n 3 for Scissors\n “)

 player_two = input(“Hi ” + name_two +  ”  enter:\n\n 1 for Rock\n 2 for Paper\n 3 for Scissors\n\n “)

Now to the engine of the program. If statements are used to evaluate each of the possible combinations. i.e. Player 1 chooses rock and Player 2 chooses paper etc.

 

 if player_one == “1” and player_two == “2”:

 print(“Paper beats Rock: ” + name_one + ” you are the winner “)

 

elif player_one == “2” and player_two == “1”:

 print(“Paper beats Rock: ” + name_two + ” you are the winner “)

 

if player_one == “2” and player_two == “3”:

print(“Scissors beats Paper ” + name_one + ” you are the winner “)

 

elif player_one == “3” and player_two == “2”:

print(“Scissors beats Paper ” + name_two + ” you are the winner “)

  

if player_one == “1” and player_two == “3”:

 print(“Rock beats Scissors ” + name_one + ” you are the winner “)

 

elif player_one == “3” and player_two == “1”:

print(“Rock beats Scissors ” + name_two + ” you are the winner “)

 

If both players pick the same option; then it is a draw.

elif player_one == player_two:
       print(” Its a draw \n”)

 

Now for the Complete program:
name_one = input(“Please enter name of Player 1 “)
name_two = input(“Please enter name of Player 2 “)
var = 1

print(“Control + C to end at any time…\n”)
while var == 1:

player_one = input(” Hi ” + name_one + ” enter:\n\n 1 for Rock, 2 for Paper, 3 for            Scissors\n\n “)

player_two = input(” Hi ” + name_two + ” enter:\n\n 1 for Rock, 2 for Paper, 3 for Scissors\n\n “)

if player_one == “1” and player_two == “2”:
        print(“Paper beats Rock: ” + name_one + ” you are the winner \n”)

elif player_one == “2” and player_two == “1”:
       print(“Paper beats Rock: ” + name_two + ” you are the winner \n”)

if player_one == “2” and player_two == “3”:
       print(“Scissors beats Paper ” + name_one + ” you are the winner \n”)

elif player_one == “3” and player_two == “2”:
      print(“Scissors beats Paper ” + name_two + ” you are the winner \n”)

if player_one == “1” and player_two == “3”:
       print(“Rock beats Scissors ” + name_one + ” you are the winner \n”)

elif player_one == “3” and player_two == “1”:
       print(“Rock beats Scissors ” + name_two + ” you are the winner \n”)

elif player_one == player_two:
       print(” Its a draw \n”)

 

 

 

 

Why I use notepad++ text editor

You have a huge choice when it comes to choosing a text editor for working with Python. IDLE itself comes with a basic built in text editor. If you want more features though you will need to look elsewhere.

There are many text editors available; Sublime Text, TextWrangler and notepad++ to name but a few.

I personally have chosen to use notepad++ as my text editor of choice. Notepad ++ is a free easy to use text editor.

notepad++

You can download notepad++ at https://notepad-plus-plus.org/download/v7.5.3.html

Unfortunately, it is only compatible with windows. (A possible alternative for Linux is Notepadqq and for Mac is Brackets)

So why did I choose notepad++ ?

Notepad++ is an elegant feature packed text editor yet it is simple to use.

The first difference you will notice between standard notepad and notepad++ is the line numbering.

notepad

Line numbering makes it easier for you to find where the errors lie in your code. The interpreter will give you the line number along with the error.

line

A feature of Notepad++ is tabbed editing. Each file is accessible via a tab on top of the page making it simple to hop between one file and another.

tabbed

Another great feature is auto completion; start typing a function name and notepad++ will give you a list of function names to choose from.

predict

Notepad++ menu is action packed, its Edit menu for instance boasts a lot of helpful features.

Select the Indent option to either increase of decrease the indention on a highlighted block of text.

indent

Likewise convert a selected block of text to all lowercase, uppercase, sentence case etc.

My personal favorite time saver from the edit menu is Comment/Uncomment. This allows you to comment out or un-comment out a block of text at once.

comment

These features are simple time savers which I find invaluable when I am typing code.

Conclusion 

This is not meant to be a comprehensive review of notepad++. Instead I just wished to give a quick outline why I personally choose to use notepad++ for my coding projects.

Feel free to leave a comment and let me no what editor you use and why. 

Paul