0% found this document useful (0 votes)
9 views26 pages

Application of ICT - Lecture 11

Uploaded by

sheryarh42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views26 pages

Application of ICT - Lecture 11

Uploaded by

sheryarh42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Applications of ICT

Instructor: Anum Ilyas


Lecture 11
Variable , Datatypes
and Expression
Variable

 reserve memory location


 name that can be assigned a
value and used to reference
that value throughout your
code.
 Variables keep values
accessible
 Variables give values
context
Statement

 an instruction, that interpreter


can execute
 Statement can create Variable,
write expressions and import
library etc.
 A computer program is actually
combination of statements.
 The most basic statement:
Assignment statement
Assignment
Operator
 Values are assigned to a
variable using a special symbol
= called the assignment
operator.
 Assignment statement create
new variables and give them
values.

 The output Hello, world is


displayed when you execute
print(phrase).
Keywords / Reserved
words
 some words which are
reserved by programming
language
 instruct interpreter to do a
specific task
Rules for valid
Variables
 Always meaningful
 Can only contain Alphabets (small and
capital), _ symbol and combination of
numbers
 Must start with either alphabet or _
symbol (better to start with alphabets)
 Case sensitive
 Age and age are two different
variable names
 Key words
 cannot be used as variable name
Rules for valid
Variables
 Case sensitive
Rules for valid
Variables

 Descriptive names are


better than short names
Rules for valid
Variables

 Naming Conventions
Comments

 notes that explain the


source code of a program.
 intended to make the
code easier for humans to
understand
 In-line comments
 Block comments
Comments

 Multi-line comment
Value and
type

Value is a Variable can


letter, be of type:
number, Number,
string that a String, bool,
program complex list,
manipulate. tuple
(2,4.4,
Number can Type illustrate
Pakistan,
of type: a) interpreter
Integer (1,2), which kind of
float (2.5) value can be
stored
Operators and
Operands
 Operators
 special symbols that represent
computation like addition, subtraction
etc
 Operands
 Values which are used by Operators
 Operands can be immediate values or
variable name.
s1 = 45
s2 = 56
total = s1+s2 #computation with
variable names
total = total + 56 #computation with
immediate value
Operators and
Operands

 Assignment: =
 Arithmetic: +, - , *,
**, / , // , %
 Relational or comparison:
==, > , < , >= , <= , !=
 Logical : and, or , not
Order of Operation

 Multiple operators in an
expression evaluates on
rule of precedence.
 PEMDAS: Parentheses,
Exponent, Multiplication,
Division, Add, Subtraction
 Operators with same
precedence are evaluated
from Left to Right
Arithmetic Expression
Arithmetic Expression

Practice:
1. result = 3 + 2 * (5 ** 2 - 3
* 2) / 4 – 6
2. result = (3 + 2 * (6 - 4)) **
2 - 10 / 2
3. result = (5 - 8) ** 2 + 6 *
3 - (12 / 4)
Arithmetic Expression

Answer:
1. result = 3 + 2 * (5 ** 2 - 3
* 2) / 4 – 6 =6.5
2. result = (3 + 2 * (6 - 4)) **
2 - 10 / 2 =44
3. result = (5 - 8) ** 2 + 6 *
3 - (12 / 4) =24
Math Functions
Math Functions

Difference between ** and pow():


Complex Numbers
Boolean
User Input

Obtain information
from user
x= input () #By default
takes string
as input
X= int(input())
#typecasting
User Input

Eval Function

You might also like