Intro to Python
By Victor K Miclovich Research scientist, AlViHe
1
A taste of what programmers do Website development Database management systems Artificial intelligence Game development Security (crypto) Information systems (e-commerce, e-business, ebanking, etc.) • Software application development • Systems development and design • • • • • •
2
Places to work • IS giants: – Google, Yahoo, MSN, etc.
• Software development – As a freelance developer – Contract developer • Microsoft, Open source (Linux), etc.
• World wide opportunities in research b’se the world is a global village and work can be got easily
3
IS – Information Systems • A way in which information can be stored, organized, and distributed to effect management decisions at an organization – You could design search engines, effective websites, good databases, etc. • Google, for example, is expanding and has an Africa office in Kenya and currently in the stage of setting up one in Uganda
4
Freelance developer
• To be able to work on various projects to earn a “living” that appears to be quite luxurious and very educational b’se you face many problems in line of duty
5
Website development • Use of open source to develop websites (the world economy is becoming even more electronic as each day passes) – Be able to work with primitive languages like HTML and XML; others like MySQL, Python, Perl, Jscript, PHP, and many others – Its quite an exciting experience
6
Artificial intelligence/intelligent systems • To develop systems with very enhanced features to boost productivity of applications and hardware (machines like robots, factory expert systems) – – – – – –
Involves a strong mathematical background Good problem solving skills Excellent programming skills Knowledge of some cognitive science (of the brain) Be well-versed with algorithms and data structures A team player; projects aren’t done by one person alone
7
Game devl’pt • Design of both 2-D and 3-D games for devices like play station, Xbox, slotting machines, etc • Computer graphics • Intelligence involved in game code!
8
Crypto or security • Should be able to design safe applications aware from cyber-criminals like crackers • Be able to control complex viruses that affect mostly hardware performance and that are hidden; known as crypto-viruses b’se of their ability to hide in software systems
9
Job opportunities • The list is endless, but the previous slides are just to show you just the tip of the ice-berg, there are a vast number of things a computer scientist (a.k.a programmer) can do; so specialize to avoid a PHD (Permanent H*** D****e)
10
Class details • This is a fully practical course – Entails a lot of programming work – Personal reading, advisable!!! – Extensive research and comparison with other languages • Over 20 lectures + assignments; this is an easy class, so no worries!!
11
Goal Use Python to create something useful Examples: • Simulate a natural/engineering process • Manipulate files/PDFs • Draw pretty graphics • And many more…
12
Why Python? Simpler syntax for beginning programmers A growing interest and support community Many online publications and support Is supported by many platforms: Mac OS, Windows™, Linux, Solaris… • It is interoperable • Has an extensive library • It is a very powerful language
• • • •
13
14
Some subtle differences • A comparison with C and Java – The hello world program Description: It prints out a string of characters: “Hello world”
15
Hello.c #include <stdio.h> int main () { printf(“hello world \n”); }
16
Hello.py print “hello world”
17
Hello.java class Hello{ public static void main(String[] args){ //Program executions starts here System.out.println(“Hello world.”); } }
18
What the previous slides show? • The degree of complexity in writing just a simple program • The level of work • How easy it is to make a mistake, and yet this is the easiest program: Hello
19
20
Intro begins now!!! ☺ What is a programming language? These are a set of rules (vocabulary and grammatical) that are used to instruct a computer to perform specific tasks such as computational operations such as addition, subtraction, file reading, and so on
21
The two languages • Natural languages
• Formal languages
22
Natural languages • Simply stated; these are languages used by human beings in their daily interactions Examples: English, Luganda, French, Swahili, etc.
23
Formal languages • Languages that are made up in order to abstract or mimic a natural process or even an engineering process. Examples include: From Chemistry: CO2, H2O… chemists tend to understand that π
tan x ∫ π , etc. From Math: ∫ sin (x + cos x ), 4 2
1
2
0
From Programming: Python, Java, C syntax: - keywords (or tokens): def, define, class, public, void, etc. The things programmers tend to understand Formal languages are also artificial languages; they don’t evolve like natural languages
24
Characteristics of programming languages
• Have the following: – Syntax rules – Semantic rules – Structure (data structure/types)
25
syntax • Refers to the grammatical rules of a programming language such when to start a statement (similar to sentence in natural languages) • In python, for example, a program is given a name definition using the keyword def • We’ll meet more of that later
26
semantics • This refers to the meaning (mostly logical) of a program when it is written • The meaning should be easily understood by a programmer
27
Types of high-level programming languages • Interpreted • compiled
28
Interpreted languages • Read (and translates) lines of code while simultaneously executing code (or instructions) • The written code (by programmer) is called the source code • The result (after running program) is called the output
Figure 1.0
The source code you type is processed by a program, called the interpreter, to produce an output
29
Compiled languages • A compiled language translates all the source code (at once) into an executable code (also called object code) which can be executed at a later time
Figure 1.1
• The compiler translates source code into object code • The executable can then be passed through an executor which evaluates expression (or your program) and gives an output
30
Then what is python? • Python is an interpreted object-oriented programming language • Other interpreted languages are LISP, MIT/SCHEME, LIMBO, Java exhibits both compilation and interpretation as will be seen later
31
Other salient features of Python™ • Python has got two modes of operation: – Script mode – Normal/interactive mode
32
Interactive mode The interactive mode is shown in figure 1.2 defined by the symbol >>>
The interactive mode can be used to immediately see the result of certain input such as statements and computations We shall see more of this! Figure 1.2
33
Script mode The script mode produces a clean work space with no interactive capabilities; so you won’t see the output or result of your program unless you save it as a *.py file and run it (F5)
Python scripts (or text files) must have a .py extension otherwise they won’t run and execute easily
Figure 1.3
34
What is programming? • Programming is merely giving a computer instructions • Before programming, it is important that you should know what it is you are trying to solve: know your assignment before hand
35
Approaches used in programming • Top-down approach: You understand what the program is supposed to do; its application You formulate a plan Gather requirements such as the input variables/values And what the program should give as an output when fed certain input – Next step usually involves splitting a large task into smaller tasks that can easily be managed: this is the essence of an OOP – – – –
36
Your first program print “hello world”
37
In the Interactive mode
Take a few shots; write the program!!!
38
Type your program; print “hello world”
Saving the program
Type file name
39
Step before the final step
Running the program!
40
Results!!!!
41
What Next?
42
References: http://www.python.org Think like a computer scientist, Learning with Python. Allen D, et. al Green Tea press
Assignment: Read from chapters 1 to 4 Next lecture briefly covers detail of these chapters
43