Python Revision Day 5
Python Revision Day 5
• Python Revision
• AI ML model Live Building
• AI ML concepts Revision
• Till 11
• 11 30 Animation using scratch
• 11 30 to 12 30 Basic Website Building
• Basics of ethical hacking
• Send Off
Constants
• Fixed values such as numbers, letters, and strings, are called
“constants” because their value does not change
• Numeric constants are as you expect
>>> print(123)
• String constants use single quotes (') 123
or double quotes (") >>> print(98.6)
98.6
>>> print('Hello world')
Hello world
Variables
• A variable is a named place in the memory where a programmer can store
data and later retrieve the data using the variable “name”
x = 12.2 x 12.2
y = 14
y 14
Reserved Words
You cannot use reserved words as variable names / identifiers
• Case Sensitive
hours = 35.0
What are these rate = 12.50
bits of code doing? pay = hours * rate
print(pay)
Sentences or Lines
x = 2 Assignment statement
print(x) Print statement
• Left to right
1 + 2 ** 3 / 4 * 5
>>> x = 1 + 2 ** 3 / 4 * 5
>>> print(x)
11.0 1 + 8 / 4 * 5
>>>
1 + 2 * 5
Parenthesis
Power
Multiplication 1 + 10
Addition
Left to Right
11
xx = 1
type (xx)
Several Types of Numbers
<class 'int’>
<class'float'>
User Input
• We can instruct Python to
pause and read data name = input('Who are you? ')
print('Welcome', name)
from the user using the
input() function
• Why comment?
for i in range(5) :
print(i)
if i > 2 :
print('Bigger than 2')
print('Done with i', i)
print('All Done')
Visualize Blocks x=4
no yes
x = 4 x>2
if x > 2 :
print('Bigger') print('Not bigger') print('Bigger')
else :
print('Smaller')
print('All done')
print('All Done')
Multi-way
yes
print('small
x<2 number')
no
if x < 2 :
yes print('Medium
print('small number')
x < 10 number')
elif x < 10 :
print('Medium number') no
else : print(‘Large
print(' Large number ') number')
print('All done')
print('All Done')
n=5 An Infinite Loop
No Yes
n>0?
n = 5
print('Lather') while n > 0 :
print('Lather')
print('Rinse’)
print('Rinse')
for i in [5, 4, 3, 2, 1] : 5
print(i) 4
3
print('Blastoff!')
2
1
Blastoff!
A Simple Definite Loop
5
for i in [5, 4, 3, 2, “Hello”] :
print(i)
4
print('Blastoff!') 3
2
Hello
Blastoff!
A Simple Definite Loop
def lyrics():
print("I'm a lumberjack, and I'm okay.")
print('I sleep all night and I work all day.')
print('Yo')
lyrics()
Hello
x = x + 2
print(x) Yo
I'm a lumberjack, and I'm okay.
I sleep all night and I work all day.
7
Return Values
Often a function will take its arguments, do some computation, and
return a value to be used as the value of the function call in the
calling expression. The return keyword is used for this.
def greet():
return "Hello" Hello Glenn
Hello Sally
print(greet(), "Glenn")
print(greet(), "Sally")
Multiple Parameters / Arguments
• We can define more than one
parameter in the function def addtwo(a, b):
definition added = a + b
return added
• We simply add more arguments
x = addtwo(3, 5)
when we call the function print(x)