Tuesday, 16 December 2014

Intro to Python: Coding

This being your first lesson in Python; there are a few things you should know:

  1. Python is un-typed: Unlike Java,C/C++ where you have to declare the variable types e.g "int <variable> , float <variable>..." Python automatically identifies these variable types.
  2. Unlike e.g C/ C++  where you can mix different variable types e.g a statement like " cout << "Hello Arthur you're " << age{e.g a float  value} << " years old!" , Python does not allow such a code(sic) on the same line. 
  3. Python IDLE can be used as a substitute for a basic calculator.

  •  to get data from a user{ string data e.g. your name } use the function "raw_input()"
  • to get numeric data from a user use the function "input()"
To print a screen output e.g. "Hello Arthur" : print("Hello Arthur") ,
 print("The quick brown fox became friends with the lazy dog")


To get user input it is ideal to prompt the user e.g "Enter Your name: ".When expecting input, you must store that input into a variable e.g. a variable called "name" ; type ... name = raw_input("Enter Your Name: ") , this will bring up an input console where the value of name will be stored in the variable name

 
For more ,the source codes are available from GitHub as a Gist   Intro to python .


Monday, 15 December 2014

Intro: set up and a few stuff.

Hello and welcome to Python. I'll take you through Python as a learner too. Python is such a dynamic language that is very easy to fall in love with. I shall not bore you with "About Python". However, if you'd like to know more about Python I suggest you visit https://www.python.org/ . For the record, Python is very easy to learn. And can run on any platform.

 So let's get to it:
In this part we shall do the set up.

  1. You'll need a Python interpreter(if you don't have one from https://www.python.org/downloads/  or alternatively(I recommend) http://dl.algorete.org/loopy/ALGORETE-Loopy-Windows64_full.exe or http://dl.algorete.org/loopy/ALGORETE-Loopy_Darwin64_full.sh or http://dl.algorete.org/loopy/ALGORETE-Loopy_Linux64_full.sh 
  2. Once you have that, typing "python" (without the quotes) on powershell-for Windows users should return the python version and invoke python IDLE on powershell (cool huh?).
  3. It's a great thing running python from IDLE but it gives you a controlled environment and you'll get thrown off when you encounter heavy stuff such as scipy, numpy, Kivy etc, so i recommend an IDE the best I've used so far- and what I'll be using is Jetbrains Pycharms from https://www.jetbrains.com/pycharm/download/


The above steps helps you set up python. In case of any problems please comment.

 For your first program on IDLE type the following after the >>> signs  and press enter: 
        print ("Hello Python")
Next post we'll get down to some coding.