filmov
tv
Lec- 7: What is an Arithmetic Operators in Python? | Examples of Operators in Python | #ai #ml #ds

Показать описание
I've decided to upload each lecture with an example of an operator to make things easier for students. Short videos are easier to watch and understand, so practice a lot. In addition, I will shortly upload lecture notes with exercises.
Please subscribe and comment because I want to improve education for all students, particularly economically challenged pupils.
Topics covered during this session:
1. Definition of Operator
2. Explained Types of Operator
3. Arithmetic Operator
4. + ----------- Addition
5. - ------------ Subtraction
6. * ------------ Multiplication
7. / ------------ Division
8. % ----------- Modulus
9. ** ----------- Exponent
10. // ---------- Floor Division
Precedence of Arithmetic Operators in Python
The precedence of Arithmetic Operators in Python is as follows:
P – Parentheses
E – Exponentiation
M – Multiplication (Multiplication and division have the same precedence)
D – Division
A – Addition (Addition and subtraction have the same precedence)
S – Subtraction
Modulus Operator (%)
Python defines the "%" symbol, also called the Percent symbol, as a modulus (or modulo) operator. It returns the remainder when the denominator divides the numerator. It is also known as the "remainder operator." The modulus operator returns the number remaining after the integer quotient. For example, when 10 is divided by 3, the quotient is 3 and the remainder is 1. Hence, 10%3 (normally pronounced as 10 mod 3) yields 1.
Exponent Operator (**).
The Python exponent operator is ** (double asterisk), also known as the raised to operator. So, for a**b, you use a raised to the bth power of a.
If both operands in the exponentiation expression are integers, the result will be an integer. If either is a float, the outcome will be float. Similarly, if either operand is a complex number, the exponent operator returns a complex number.
If the base is 0, the result is zero, and if the index is 0, the result is always one.
Floor Division Operator (//)
Floor division is also known as integer division. Python achieves this through the use of the // (double forward slash) symbol. Unlike modulus and modulo, which return the remainder, floor division returns the quotient of the operand division.
If both operands are positive, the floor operator returns a number with the fractional part removed. For example, the floor division of 9.8 by 2 yields 4 (pure division is 4.9; remove the fractional part, yields 4).
If one of the operands is negative, the result is rounded away from zero (to negative infinity). Floor division of -9.8 by 2 yields 5 (pure division is -4.9, rounded away from zero).
Question #1:
Create a simple basic calculator program in Python.
Direction:
Your program should be dynamic, accept two numbers from the user, and perform the following calculations:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. modulus
6. Exponents
7. Floor division
Question #2:
Create a Python program that takes in a student's name, class, and section. It should also take into account the students' five subject marks to calculate their total mark and percentage. Display the result with their name, class, section, and percentage printed.
Follow me on:
Please subscribe and comment because I want to improve education for all students, particularly economically challenged pupils.
Topics covered during this session:
1. Definition of Operator
2. Explained Types of Operator
3. Arithmetic Operator
4. + ----------- Addition
5. - ------------ Subtraction
6. * ------------ Multiplication
7. / ------------ Division
8. % ----------- Modulus
9. ** ----------- Exponent
10. // ---------- Floor Division
Precedence of Arithmetic Operators in Python
The precedence of Arithmetic Operators in Python is as follows:
P – Parentheses
E – Exponentiation
M – Multiplication (Multiplication and division have the same precedence)
D – Division
A – Addition (Addition and subtraction have the same precedence)
S – Subtraction
Modulus Operator (%)
Python defines the "%" symbol, also called the Percent symbol, as a modulus (or modulo) operator. It returns the remainder when the denominator divides the numerator. It is also known as the "remainder operator." The modulus operator returns the number remaining after the integer quotient. For example, when 10 is divided by 3, the quotient is 3 and the remainder is 1. Hence, 10%3 (normally pronounced as 10 mod 3) yields 1.
Exponent Operator (**).
The Python exponent operator is ** (double asterisk), also known as the raised to operator. So, for a**b, you use a raised to the bth power of a.
If both operands in the exponentiation expression are integers, the result will be an integer. If either is a float, the outcome will be float. Similarly, if either operand is a complex number, the exponent operator returns a complex number.
If the base is 0, the result is zero, and if the index is 0, the result is always one.
Floor Division Operator (//)
Floor division is also known as integer division. Python achieves this through the use of the // (double forward slash) symbol. Unlike modulus and modulo, which return the remainder, floor division returns the quotient of the operand division.
If both operands are positive, the floor operator returns a number with the fractional part removed. For example, the floor division of 9.8 by 2 yields 4 (pure division is 4.9; remove the fractional part, yields 4).
If one of the operands is negative, the result is rounded away from zero (to negative infinity). Floor division of -9.8 by 2 yields 5 (pure division is -4.9, rounded away from zero).
Question #1:
Create a simple basic calculator program in Python.
Direction:
Your program should be dynamic, accept two numbers from the user, and perform the following calculations:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. modulus
6. Exponents
7. Floor division
Question #2:
Create a Python program that takes in a student's name, class, and section. It should also take into account the students' five subject marks to calculate their total mark and percentage. Display the result with their name, class, section, and percentage printed.
Follow me on: