CF Chapter-005
CF Chapter-005
CF Chapter-005
C E – 119
Computing Fundamentals (CF)
Compiled By:
2
CE - 119 : Computing Fundamentals (CF)
Course Learning Outcomes ( CLO )
CLO Level
Outcome Statement
No. *
Explain the fundamental knowledge and concepts about
1 computing infrastructure including hardware, software, C2
database and networks.
Applying and Implementing number systems and logic
2 C3
gates.
Text Books
1. Computing Essentials, Timothy O’Leary and Linda O’Leary
2. Introduction to Computers, Peter Norton, 6th Edition, McGraw-Hill
3. Introduction to Programming using Python, Daniel Liang
4. Turbo C Programming For The PC, Robert Lafore, Revised Edition
Reference Books:
1. Discovering Computers, Misty Vermaat and Susan Sebok,
Cengage Learning
2. Using Information Technology: A Practical Introduction to Computers
& Communications, Williams Sawyer, 9th Edition, McGraw-Hill
3. Introduction to Python, Paul Deitel, Harvey Deitel
4. Let Us C, Yashavant Kanetkar 4
Marks Distribution
https://sites.google.com/view/muzammil2050
5
Course Instructors
6
CE – 119: Computing Fundamentals Chapter
5
Introduction to
Programming Environment
Compiled By:
Engr. Syed Atir Iftikhar satir@ssuet.edu.pk
7
Objectives
To write and run a simple Python program
To explain the basic syntax of a Python program
To describe the history of Python
To explain the importance of, and provide examples of,
proper programming style and documentation
To explain the differences between syntax errors,
runtime errors, and logic errors
To create a basic graphics program using Turtle
8
Computer Programming
9
Programs
1101101010011010
11
Programming Languages
Machine Language Assembly Language High-Level Language
…
Assembler …
ADDF3 R1, R2, R3
1101101010011010
…
…
12
Programming Languages
Machine Language Assembly Language High-Level Language
area = 5 * 5 * 3.1415;
13
Popular High-Level Languages
COBOL (COmmon Business Oriented Language)
FORTRAN (FORmula TRANslation)
BASIC (Beginner All-purpose Symbolic Instructional Code)
Pascal (named for Blaise Pascal)
Ada (named for Ada Lovelace)
C (whose developer designed B first)
Visual Basic (Basic-like visual language developed by Microsoft)
Delphi (Pascal-like visual language developed by Borland)
C++ (an object-oriented language, based on C)
C# (a Python-like language developed by Microsoft)
Python (We use it in the book)
14
Compiling Source Code
A program written in a high-level language is called a
source program. Since a computer cannot understand a
source program.
Program called a compiler is used to translate the
source program into a machine language program
called an object program. The object program is often
then linked with other supporting library code before
the object can be executed on the machine.
Library Code
15
Operating Systems
The operating system (OS) is a
program that manages and controls User
a computer’s activities. You are
probably using Windows 10 or Application Programs
18
Flow Chart
Name Symbol Use in Flowchart
Decision
Connector Data Flow
20
Algorithm and Pseudo code (Example 1)
21
Algorithm and Pseudo code (Example 1)
Pseudo code:
1. Input a set of 4 marks
2. Calculate their average by summing and dividing by 4
3. if average is below 50
4. Print “FAIL”
5. else
6. Print “PASS”
22
Algorithm and Pseudo code (Example 1)
Algorithm
Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif 23
Algorithm and Pseudo code (Example 1)
START
Input M1,M2,M3, M4
GRADE ( M1 + M2 + M3 + M4 ) / 4
N Y
IS GRADE <
50
PRINT PRINT
“ PASS ” “ FAIL ”
STOP 24
Algorithm and Pseudo code (Example2)
Algorithm START
STOP
26
3 Computer Programming Construct
27
3 Computer Programming Construct
F T F T
28
What is Python?
General Purpose Interpreted Object-Oriented
29
What is Python?
General Purpose Interpreted Object-Oriented
30
What is Python?
General Purpose Interpreted Object-Oriented
Open source
32
Python 2 vs. Python 3
Python 3 is a newer version, but it is not backward
compatible with Python 2.
33
Launch Python
34
Launch Python IDLE
35
Run Python Script
36
A Simple Python Program
Listing 1.1
# Display two messages
print("Welcome to Python")
print("Python is fun")
37
Creating and Editing Using Notepad
To use Notepad, type
notepad Welcome.py
from the DOS prompt.
38
animation
39
animation
40
41
Program 1.1 WelcomeWithThreeMessages.py
print("Welcome to Python")
print("Python is fun")
print("Problem Driven")
Output:
Welcome to Python
Python is fun
Problem Driven
42
Program 1.2 ComputeExpression.py
# Compute expression
Output:
0.397590361446
43
Anatomy of a Python Program
Statements
Comments
Indentation
44
Statement
A statement represents an action or a sequence of actions.
The statement print("Welcome to Python") in the
program in Listing 1.1 is a statement to display the
greeting "Welcome to Python“.
# Display two messages
print("Welcome to Python")
print("Python is fun")
45
Indentation
The indentation matters in Python. Note that the
statements are entered from the first column in the new
line. It would cause an error if the program is typed as
follows:
# Display two messages
print("Welcome to Python")
print("Python is fun")
46
Special Symbols
Character Name Description
" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
''' ''' Opening and closing Enclosing a paragraph comment.
quotation marks
47
Programming Style and Documentation
Appropriate Comments
48
Appropriate Comments
Indentation
Indent four spaces.
A consistent spacing style makes programs clear
and easy to read, debug, and maintain.
Spacing
Use blank line to separate segments of the code.
50
Programming Errors
Syntax Errors
Error in code construction
Runtime Errors
Causes the program to abort
Logic Errors
Produces incorrect result
51
Escape Sequence
Escape Sequences are used
Code Description
to signal an alternative
\’ Single Quote
interpretation of a series of
\” Double Quote
characters.
\\ Back Slash
It interrupts the normal flow
\b Backspace
of output value.
An escape character is a \n New Line
print("Greetings \nSir")
Output:
Greetings
Sir
Welcome to the world of "Programming"
nice day...
53
Getting Started with GUI Programming
Why GUI? Turtle Tkniter
54
Getting Started with GUI Programming
Why GUI? Turtle Tkniter
55
Getting Started with GUI Programming
Why GUI? Turtle Tkniter
56
Getting Started with GUI Programming
Why GUI? Turtle
59
Method Parameter Description
Turtle() None Creates and returns a new turtle object
forward() amount Moves the turtle forward by the specified amount
backward() amount Moves the turtle backward by the specified amount
right() angle Turns the turtle clockwise
left() angle Turns the turtle counterclockwise
penup() None Picks up the turtle’s Pen
pendown() None Puts down the turtle’s Pen
up() None Picks up the turtle’s Pen
down() None Puts down the turtle’s Pen
color() Color name Changes the color of the turtle’s pen
fillcolor() Color name Changes the color of the turtle will use to fill a polygon
heading() None Returns the current heading
position() None Returns the current position
goto() x, y Move the turtle to position x,y
begin_fill() None Remember the starting point for a filled polygon
end_fill() None Close the polygon and fill with the current fill color
dot() None Leave the dot at the current position
stamp() None Leaves an impression of a turtle shape at the current location
shape() shapename Should be ‘arrow’, ‘classic’, ‘turtle’ or ‘circle’ 60
Getting Started with GUI Programming
Why GUI? Turtle