Application Development
Application Development
• The min() and max() functions can be used to find the lowest or
highest value in an iterable:
• Python has also a built-in module called math, which extends the list
of mathematical functions
• To use it, you must import the math module: PYTHON MATH MODULE
• Python has a built-in module that you can use for mathematical
tasks.
• The math module has a set of methods and constants.
• When you have imported the math module, you can start using
methods and constants of the module.
• The math,sqrt() method for example, returns the square root of a
number
INDENTATION
ELIF
PYTHON IF… ELSE
• The elif keyword is python way of using “if previous conditions were
PYTHON CONDITIONS AND IF STATEMENTS not true, then try this conditions”.
• Python supports the usual logical conditions from mathematics:
o Equals: a == b
o Not Equals: a != b
o Less than: a < b
o Less than or equal to: a <= b
o Greater than: a > b
o Greater than or equal to: a >= b
• These conditions can be used in several ways, most commonly in ”IF
STATEMENT” and LOOPS. • In this example a is equal to b, so the first conditions is not true, but
the elif condition is true, so we print to screen that “a and b are
• An “IF STATEMENT” is written by using the if keyword
equal”.
ELSE SHORT HAND IF…ELSE
• The else keyword catches anything which isn’t caught the preceding • If you have only one statement to execute, one for if, and one for
conditions. else, you can put it all on the same line:
• In this example a is greater than b, so the first conditions is not true, • You can also have multiple else statement on the same line:
also the elif condition is not true, so we go to the else condition and
print to screen that “a is greater than b”
• You can also have an else without the elif:
AND
SHORT HAND IF
• If you have only one statement to execute, you can put it on the
same line as the if statement.
OR
NESTED IF
• With the break statement we can stop the loop even if the while
conditions is true
• With the else statement we can run a block of code once when the
condition no longer is true:
PYTHON FOR LOOPS
• A for loop is used for iterating over a sequence (that is either a list, a
tuple, a dictionary, a set, or a string)
• This is less like the for keyword in other programming languages, THE CONTINUE STATEMENT
and works more like an iterator method as found in other object- • With the continue statement we can stop the current iteration of
oriented programming languages. the loop, and continue with the next:
• With the for loop we can execute a set of statement, once for each
item in a list, tuple, set, etc.
• The for loop does not require an indexing variable to set beforehand THE RANGE() FUNCTION
LOOPING THROUGH A STRING • The loop through a set of code a specified number of times, we can
use the range() function,
• Even strings are iterable objects, the contain a sequence of • The range() function returns a sequence of numbers, starting from 0
characters: by default, and increments by 1 (by default), and ends at a specified
number.
• With the break statement we can stop the loop before it has looped
all the items:
ELSE IN FOR LOOP
NESTED LOOPS
• For loops cannot be empty but if you for some reason have a for
loop with no content, put in the pass statement to avoid getting an
error.