Uploaded by tonny muhiya

Chaper 2 Part 1

advertisement
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
DEV1A01: Development Software 1A01
Unit 2 (Part 1): First Look at Python! !
Dr Abejide Ade-Ibijola1
1 Department of Applied Information Systems
2019
Dr Abejide Ade-Ibijola
DEV1A01
2019
1 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Content
1
Python
2
Interpreter vs Compiler
3
Why Python ?
4
Versions
5
Run Python programs on Command Line
6
Using Notepad++ and Python Interpreter
7
Some implementations
Dr Abejide Ade-Ibijola
DEV1A01
2019
2 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Python !
Multi-paradigm : Object-oriented, imperative, functional, procedural, and reflective.
Designed by : Guido van Rossum (A Dutch programmer). Worked at Google, now
at Dropbox (as at 2017).
https://www.python.org/~guido/.
Python is an interpreted language.
An interpreter is a computer program that directly executes, i.e. performs,
instructions written in a programming or scripting language, without previously
compiling them into a machine language program.
Dr Abejide Ade-Ibijola
DEV1A01
2019
3 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Interpreter vs Compiler
Dr Abejide Ade-Ibijola
DEV1A01
2019
4 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Interpreter vs Compiler..2
Dr Abejide Ade-Ibijola
DEV1A01
2019
5 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Why Python ?
High-level language, can do a lot with relatively little code
Supposedly easier to learn than its main competitors
Fairly popular among high-level languages
Robust support for object-oriented programming
Support for integration with other languages
Version 2 and 3 (majorly used)
We will write our programs in Version 3
Dr Abejide Ade-Ibijola
DEV1A01
2019
6 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Versions
Assignment : what are the major differences
between Version 2 and Version 3 of Python
programming language ?
Get some references here :
http://sebastianraschka.com/Articles/2014_
python_2_3_key_diff.html
Dr Abejide Ade-Ibijola
DEV1A01
2019
7 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Run Python on Shell
Dr Abejide Ade-Ibijola
DEV1A01
2019
8 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Run Python with Notepad++/CMD
Launch Notepad++
Dr Abejide Ade-Ibijola
DEV1A01
2019
9 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
More ?
Hello world !
print (“Hello World !”)
Multiply strings
print ("whatsup" * 3)
Try For Loops
for x in range(0, 3) :
print (x)
Extend this to display only 1 to 100, using the variable “count” in
place of “x”
Dr Abejide Ade-Ibijola
DEV1A01
2019
10 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Run Python from Command Line
-Pick a Text Editor
- Notepad, Notepad++, or Atom, etc
-Create a directory on drive C : for all your programs, call it your
<student_number>_programs
-Write your code in a text document, and save it in the directory above
-Save your file with the extension .py
-Launch Windows Command Prompt
Run -> cmd.exe
-Go to your directory, using cd.. for backwards and cd for forward
navigations.
Run your code with this command :
python filename.py
Dr Abejide Ade-Ibijola
DEV1A01
2019
11 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Implementation of earlier algorithms
Factorial of 5
factorial = 1
for i in range(1,6):
factorial = factorial * i
print("The factorial of 5 is ",factorial)
Factorial of any given number ?
Use the keyword “input” as follows :
num = input (“What number do you want to know the factorial of?”)
Hint : Use int for type casting.
Dr Abejide Ade-Ibijola
DEV1A01
2019
12 / 13
Python Interpreter vs Compiler Why Python ? Versions Run Python programs on Command Line Using Notepad++ and Python Interpreter Some implem
Implementation of earlier algorithms..2
Factorial of n, in python.
num = input (“What number do you want to know the factorial of?”)
factorial = 1
for i in range(1,num + 1):
factorial = factorial * i
print("The factorial of ", num , " is " , factorial)
Dr Abejide Ade-Ibijola
DEV1A01
2019
13 / 13
Download