Professional Documents
Culture Documents
ITP-Day 3 - Deck
ITP-Day 3 - Deck
gaurrohit0071@gmail.com
STB6BGNELH
○ Loops
○ For Loop
○ While Loop
○ List Comprehension
This file is meant for personal use by gaurrohit0071@gmail.com only.
Sharing or publishing
Proprietary content. © Great the contents
Learning. in partUnauthorized
All Rights Reserved. or full isuse
liable for legal
or distribution action.
prohibited.
Let’s explore conditional statements
● Conditional statements:
○ If statement
○ If-else statement
○ If elif else statement
○ Nested if-else This file is meant for personal use by gaurrohit0071@gmail.com only.
Sharing or publishing
Proprietary content. © Great the contents
Learning. in partUnauthorized
All Rights Reserved. or full isuse
liable for legal
or distribution action.
prohibited.
If Statement
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
●
STB6BGNELH
Python logical conditions supported are
○ Equivalence `==`
○ Inequivalence `!=`
○ Less than `<`
○ Greater than `>`
○ Less than or equal to `<=`
○ Greater than or equal to `>=`
● If statement can be nested
This file is meant for personal use by gaurrohit0071@gmail.com only.
Sharing or publishing
Proprietary content. © Great the contents
Learning. in partUnauthorized
All Rights Reserved. or full isuse
liable for legal
or distribution action.
prohibited.
If statement
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
● The statement(s) under ‘else:’ are executed when the condition in ‘if ’ is not
satisfies, ie., the boolean output is ‘False’
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
● Elif statement is used to control multiple conditions only if the given if condition is
false
● It's similar to an if-else statement and the only exception is that in else we are not
checking the condition but in elif, we check the condition
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
● Note that the ‘if’ statements are within the body of another if statement
● If the first ‘if’ condition is satisfied then the program executes the
commands within that ‘if’
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
• Iterable is a Python object that is capable of returning its elements (or members)
one by one
gaurrohit0071@gmail.com
STB6BGNELH
• Sequence type Python objects like lists, tupes, dictionaries, strings and sets are
iterable type of objects
gaurrohit0071@gmail.com
STB6BGNELH
Iteration is a general term for taking each item from a sequence one after another
No
gaurrohit0071@gmail.com
STB6BGNELH
Is the N0
gaurrohit0071@gmail.com conditio
STB6BGNELH n met?
Yes
Print the element,
increment the value,
pass control to while Increment x by 1 and pass the control to the
statement while statement
End loop
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
● But at times, due to certain factors, we may want to:
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
This fileHere
is meant the forstep
personal is setuse by togaurrohit0071@gmail.com
2. only.
Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Loop through a range (negative step)
gaurrohit0071@gmail.com
STB6BGNELH
A range() function takes 3 parameters. Start, stop and step. If
step is not provided a default step of 1 is considered.
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
A dictionary object
gaurrohit0071@gmail.com
STB6BGNELH
For loop
gaurrohit0071@gmail.com
STB6BGNELH
1st indentation
Nested loop 2nd indentation
This file is meant for personal use by gaurrohit0071@gmail.com only.
Sharing or publishing
Proprietary content. © Great the contents
Learning. in partUnauthorized
All Rights Reserved. or full isuse
liable for legal
or distribution action.
prohibited.
Nested for loop
Outer loop
gaurrohit0071@gmail.com
STB6BGNELH
Inner loop
gaurrohit0071@gmail.com
STB6BGNELH
Outer loop
Inner loop
gaurrohit0071@gmail.com
STB6BGNELH
Using the while loop update the
sum and counter
The else part is executed if the condition in the while loop evaluates to False
gaurrohit0071@gmail.com
STB6BGNELH
Initialize the counter
● Using list
gaurrohit0071@gmail.com
STB6BGNELH
comprehensions reduces the number of code lines making it. It look more
elegant
It consists of [ ] containing:
● an input sequence
gaurrohit0071@gmail.com
●
STB6BGNELH
a variable representing numbers of the input
sequence
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
gaurrohit0071@gmail.com
STB6BGNELH
Thank You