Taught by: Hisham Othman
Slides are based on: Prof. Dr. Slim Abdennadher’s slides
German University Cairo, Department of Media Engineering and Technology
Objectives Today
Recall from previous lecture
Basic DataTypes
Numeric
Integers (non-decimal)
Float (decimal)
String
Boolean
What an Algorithm is
Sequential
Input operations
Output operations
Naming a variable
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Objectives Today
Recall from previous lecture
Basic DataTypes
Numeric
Integers (non-decimal)
Float (decimal)
String
Boolean
What an Algorithm is
Sequential
Naming a variable
Input operations
Output operations
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Recall: Datatypes
In Python, every value has a datatype
How does Python know the datatype? Based on each
variable’s original assignment, Python figures out what type
it is and keeps tracks of that internally
Some Python native datatypes:
Numbers can be integers (1 and 2), floats (1.1 and 1.2)
Strings are sequences of Unicode characters (”CSEN 102”)
Booleans are either True or False
You can use the type() function to check the type of any
value or variable.
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Recall:
What is an algorithm?
An algorithm is a well-ordered collection of unambiguous and
effectively computable operations that, when executed,
produces a result and halts in a finite amount of time.
What is a computing agent?
Desktop
Smartphone
netbook
tablet
…. etc.
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Python: Variables
A variable is a named storage
A value can be stored into it, overwriting the previous
value
Its value can be copied
Example Variable
A = 3 Statement
The variable A holds the value three after its execution
Same as: add 1 to the value of A (A is now 4)
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Python: Variables
A variable is a named storage
A value can be stored into it, overwriting the previous
value
Its value can be copied
Example Variable
A = 3 Statement
The variable A holds the value three after its execution
A = A + 1
Same as: add 1 to the value of A (A is now 4)
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Python: Variables
A variable is a named storage
A value can be stored into it, overwriting the previous
value
Its value can be copied
Example Variable
A = 3 Statement
The variable A holds the value three after its execution
R.H.S. is evaluated first
A = A + 1
Then stored in the L.H.S. variable
Same as: add 1 to the value of A (A is now 4)
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
A=A+1
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Variables Naming
Choose a name for your variable
that is meaningful
Instead of naming a variable:
x, y
Name it:
age, dose
This makes reading your
algorithm easier
For the grader
For you later on
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Variables Naming
Choose a name for your variable
that is meaningful
Instead of naming a variable:
x, y
Name it:
age, dose
This makes reading your
algorithm easier
For the grader
For you later on
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Variables Naming
Python is case-sensitive
This applies to the names of the variables:
Meaning: if your algorithm includes variable(s) “Dose” and “dose”, they will
be considered two different variables
This also applies to the commands and functions:
For example: “Print()” and “PRINT()” will not work
Only “print()” will work
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Variables Naming: Can’s
Variable names can be of any length:
Example:
XylometazolineDose √
Variable names can contain:
Letters: a, b, c, …, z, A, B, C, …, Z
Example:
dose √
Numbers: 0, 1, 2, …, 9
dose12 √
Underscore: _
Xylometazoline_dose √
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Long variable name
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Variables Naming: Can’s
Variable names can be of any length:
Example:
XylometazolineDose √
Variable names can contain:
Letters: a, b, c, …, z, A, B, C, …, Z
Example:
dose √
Numbers: 0, 1, 2, …, 9
dose12hr √
dose24hr √
Underscore: _
Xylometazoline_dose √
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Variable name with 2 words
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Variable name containing numbers
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Variables Naming: Cannot’s
Variable names can NOT start with a number.
2dose
Variable names can NOT contain space:
patient age
drug dose
But:
You can use under_score, instead:
patient_age
drug_dose
Or, you can use camelCase
patientAge
drugDose
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Algorithms: operations
Algorithms can be constructed by the following
operations:
Sequential Operation
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Algorithms: operations
Algorithms can be constructed by the following
operations:
Conditional Operation
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Algorithms: operations
Algorithms can be constructed by the following
operations:
Iterative Operation
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Algorithms: operations
Algorithms can be constructed by the following
operations:
Sequential Operation Conditional Operation Iterative Operation
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Sequential Operations
Each step is performed in the order in which it is
written
Example (1)
Write an algorithm that given two
Strings returns their sum (concatenation)
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Sequential Operations
Each step is performed in the order in which it is
written
Get inputs
Example (1)
Write an algorithm that given two Compute
Strings returns their sum (concatenation) sum
Print
output
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Python-code:
Input/output and computation
Input operations:
allow the computing agent to receive from the outside
world data values to use in subsequent computations.
General Format:
<variable>= input()
<variable>= int(input())
<variable>= eval(input())
…
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Python-code:
Input/output and computation
Input operations:
allow the computing agent to receive from the outside
world data values to use in subsequent computations.
General Format:
name = input()
age = int(input())
weight = eval(input())
…
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
String input
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Python-code:
Input/output and computation
Input operations:
allow the computing agent to receive from the outside
world data values to use in subsequent computations.
General Format:
name = input()
age = int(input())
weight = eval(input())
…
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Python-code:
Input/output and computation
Input operations:
allow the computing agent to receive from the outside
world data values to use in subsequent computations.
General Format:
name = input()
age = int(input())
weight = eval(input())
…
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Numeric input
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Concatenating number strings
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Python-code:
Input/output and computation
Output operations:
allow the computing agent to communicate results of the
computations to the outside world.
General Format:
print("text”)
print(“text” , ”another text”)
print(<variable>)
print(<variable>, <another variable>)
…
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Print string and variable
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Input prompt
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Python-code:
Input/output and computation
Output operations:
allow the computing agent to communicate results of the
computations to the outside world.
General Format:
print("text”)
print(“text” , ”another text”)
print(<variable>)
print(<variable>, <another variable>)
…
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
# Comments:
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Resources
Python debugger (Student Domain)
[Link]
20Engineering%20Technology/Software/python-
debugger/
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman
Any Question?
Course Code: CSIS104 Course Title : Introduction to Computer Science Taught by: Hisham Othman