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 .


No comments:

Post a Comment