ICT Final Exam Prep - Intoduction To Python & More About Python
ICT Final Exam Prep - Intoduction To Python & More About Python
Python:
Is object oriented
Operators are special symbols used to tell a language translator what to do with variables and values
There are four kinds of operators in Python. Details of each type are listed below:
Page 2 of 7
ICT Final Exam Prep Notes (by Palwasha Ahmed 8A-1)
Chapter 07 – Introduction to Python & Chapter 08 – More About Python
Page 3 of 7
ICT Final Exam Prep Notes (by Palwasha Ahmed 8A-1)
Chapter 07 – Introduction to Python & Chapter 08 – More About Python
Used to display something on the screen. "Welcome to Python" will appear on the screen. After
print() Program flow returns to next statement in print("Welcome to Python") that the next instruction in the python program will
the Python code be executed
Page 4 of 7
ICT Final Exam Prep Notes (by Palwasha Ahmed 8A-1)
Chapter 07 – Introduction to Python & Chapter 08 – More About Python
Conditional Functions : They are only executed when required conditions are met
Loop Fuctions : They keep being executed untill the required conditions become false
Command Uses Syntax Effect
range() is a counting function. It uses a variable 'a' to
keep track of number of iterations. 'a' starts from the
Used to repeat a part of Python code by a first number (1) in the range() function. After each
desired number of times. Number of for a in range(1,4,2): iteration of the for loop, value of 'a' increases by the
iterations can be defined using the range() third number (2) in the range() function. for loop is
for function as shown. for loops are useful when exited when value of 'a' reaches the middle number
number of iterations are known. for (4) in the range() function. So for this example output
statements should end with ":". Commands print("a=", a) would be: (following will appear on the screen)
under for statements should have an indent
a=1
a=3
Value of variable 'b' is set in the bigging as 3. Value of
variable 'a' can be set too. while statement will
continue to be executed as long as the value of
Used to repeat a part of Python code variable 'a' stays less than 'b'. For this example, value
multiple times but the required number of a=1, b=3
of 'b' is known, but if the value of 'b' was being
iterations are not known. while statements
while entered by the user, the value would not be known.
should end with ":". Commands under while while a<b: The while statement would be very useful then. For
statements should have an indent before this example, output would be:
print("a=", a)
them
a=a+1
a=1
a=2
Page 6 of 7
ICT Final Exam Prep Notes (by Palwasha Ahmed 8A-1)
Chapter 07 – Introduction to Python & Chapter 08 – More About Python
Jump Statements : Python has two jump statements. They enable you to restart or come out of loops (iterations)
a=1, b=3 When the value of variable ‘a' becomes more than
the value of variable 'b', the if loop will not be
Used to jump out or "break out" of the loop executed. At that point the statement right after the
or iteration of code. When the break if a>b: if loop will be executed. The output for this example
break statement is executed the program flow goes will be:
to the very next Python code line that is after break a=1
the loop.
print("a=", a) a=2
a=a+1 a=3
print("All done") All done
a=1, b=4 Values of variables 'a' and 'b' are set. Each iteration
Used to jump back in and start the next next while a<b: of the while statement increases the value of 'a' by
iteration of a loop if a condition is true. When '1'. If 'a' becomes equal to 'b' while loop is started
a=a+1 again till the condition a<b is no longer true.
the continue statement is executed the if a==b
continue Outcome for the above code will be:
program flow ignore the remaining
instruction in the loop and starts the loop continue
again. print("a=", a) a=2
print("All done") a=3
All done
Page 7 of 7
int( ) is a Python ICT Final Exam Prep Notes (by Palwasha Ahmed 8A-1)
function. It will
= is an convert the
X is a variable. When user assignment user’s input to an input( ) is a What is your
types his age, it will be operator. It is integer. Anything typed
Python function. name? This
saved as X assigning the Otherwise user’s between the “ ”
It stops the sentence will
user’s input (age) input (age) will will be displayed
program control appear on the
to the variable X be considered a on the screen as
flow until user screen as it is
string it is
enters his input written between
(age) double quotes
Different parts of a
Value of X was
sentence should be
print() function Everything saved in the
Everything separated by
will cause the written between computer
written in ““ will commas ‘,’.
items between double quotes memory because
appear on the Everything between
the brackets ( ) to “ “ will appear on of the input()
screen as it is “ “ will be displayed
appear on the the screen as it is function. It will
as is. Value of ‘X’
screen be taken from
will be taken from
there and printed
computer memory
ICT Final Exam Prep Notes (by Palwasha Ahmed 8A-1)
When this line of Python code is
run the following message
appears on the screen. The
program waits for the user to X=int(input(“What is your age?”))
type a value.
User’s answer (15) is saved as an integer. Now
math operations can be performed on it.
Computer Screen
print(“You are“, X, “years old“) Computer Memory