0% found this document useful (0 votes)
18 views9 pages

Application Development

- Python has built-in math functions like min(), max(), abs(), and pow() to perform mathematical tasks on numbers. It also has a math module that extends the list of mathematical functions and contains methods like sqrt(), ceil(), floor(), and constants like pi. - Python uses conditional statements like if, elif, else to check conditions. Operators like ==, !=, <, <=, >, >= can be used to check equality, inequality, lower/greater values. Indentation is used to define scope. - Python has while and for loops to repeat execution of code. While loops check a condition, for loops iterate over sequences. Statements like break, continue, else can control loop behavior.

Uploaded by

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

Application Development

- Python has built-in math functions like min(), max(), abs(), and pow() to perform mathematical tasks on numbers. It also has a math module that extends the list of mathematical functions and contains methods like sqrt(), ceil(), floor(), and constants like pi. - Python uses conditional statements like if, elif, else to check conditions. Operators like ==, !=, <, <=, >, >= can be used to check equality, inequality, lower/greater values. Indentation is used to define scope. - Python has while and for loops to repeat execution of code. While loops check a condition, for loops iterate over sequences. Statements like break, continue, else can control loop behavior.

Uploaded by

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

APP DEV (WEEK 1 PYTHON MATH) PYTHON

• Python has a set of built-in math functions, including an extensive


MATH (OPERATOR) IN PYTHON
math module, that allows you to perform mathematical task on
numbers.

BUILT-IN MATH FUNCTIONS

• The min() and max() functions can be used to find the lowest or
highest value in an iterable:

• The abs() function returns the absolute(positive) value of the


specified number:

• The pow(x,y) function returns the value of x to the power of y(xy)

THE MATH MODULE

• 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

• The math.ceil() method rounds a number upwards to its nearest


integer, and the math.floor() method rounds a number downwards
to its nearest integer, and return the result:

• The math.pi constant, return the value of PI(3.14..)


APP DEV (WEEK 2 PYTHON CONDITIONS) • In this example we used two variables, a and b, which are used as
part of the if statement to test whether b is greater than a. As a is
LOOPS AND CONDITIONAL STATEMENTS 33 , and b is 200, we know that 200 is greater than 33, and so we
print to screen that “b is greater than a”.

INDENTATION

• Python relies on indentation (whitespace at the beginning of a line)


to define scope in the code. Other programming languages often
use curly-brackets for this purpose.

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

• The and keyword is a logical operator, and is used to combine


conditional statements:

SHORT HAND IF

• If you have only one statement to execute, you can put it on the
same line as the if statement.
OR

• The or keyword is a logical operator and is used to combine logical


statements:

NESTED IF

• You can have if statement insides if statement, this called nested if


statement

THE PASS STATEMENT

• If statement cannot be empty, but if you for some reason have an if


statement with no content, put in the pass statement to avoid
getting an error.
APP DEV (WEEK 3 PYTHON LOOPS)

• The while loop requires relevant variables to be ready, in this


example we need to define an indexing variable, i, which we set to 1

THE BREAK STATEMENT

• With the break statement we can stop the loop even if the while
conditions is true

THE CONTINUE STATEMENT


PYTHON WHILE LOOPS
• With the continue statement we can stop the current iteration, and
PYTHON LOOPS continue with the next:

• Python has two primitive loop commands:


o While loops
o For loops

THE WHILE LOOP

• With the while loop we can execute a set of statements as long as a


condition is true THE ELSE STATEMENT

• With the else statement we can run a block of code once when the
condition no longer is true:
PYTHON FOR LOOPS

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.

THE BREAK STATEMENT

• With the break statement we can stop the loop before it has looped
all the items:
ELSE IN FOR LOOP

• The else keyword in a for loop specifies a block of code to be


executed when the loop is finishes:

NESTED LOOPS

• A nested loop is a loop inside the loop


• The “inner loop” will be executed one time for each iteration of the
“outer loop”:

THE PASS STATEMENT

• 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.

You might also like