Lab 3
Lab 3
Lab#03
OBJECTIVE
The Purpose of the lab is to Understand the Operators and input().output() function in
Python Programming.
THEORY
PYTHON OPERATORS
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
Arithmetic operators
+ Addition 5 + 2 = 7
- Subtraction 4 - 2 = 2
* Multiplication 2 * 3 = 6
/ Division 4 / 2 = 2
// Floor Division 10 // 3 = 3
% Modulo 5 % 2 = 1
** Power 4 ** 2 = 16
Assignment operators
= Assignment Operator a = 7
+= Addition Assignment a += 1 # a = a + 1
Lab#03
-= Subtraction Assignment a -= 3 # a = a - 3
*= Multiplication Assignment a *= 4 # a = a * 4
/= Division Assignment a /= 3 # a = a / 3
%= Remainder Assignment a %= 10 # a = a % 10
Comparison operators
Logical operators
Logical AND:
and a and b
True only if both the operands are True
Logical OR:
or a or b
True if at least one of the operands is True
Logical NOT:
not not a
True if the operand is False and vice-versa.
Identity operators
is True if the operands are identical (refer to the same object) x is True
is not
True if the operands are not identical (do not refer to the same x is not
Lab#03
object) True
Membership operators
Bitwise operators
OPERATOR PRECEDENCE
Operator Description
() Parentheses
** Exponentiation
^ Bitwise XOR
| Bitwise OR
== != > >= < <= is is not in not Comparisons, identity, and membership
in operators
And AND
Or OR
input() function
the input() function allows user input.
Example:
Output:
Hello sana
Example:
Exercise
1. Create a program that prompts the user to input two numeric values (an integer
and a float) and displays the data types of those values.
2. Create a program that prompts the user to input any number, checks whether it
is between 1 and 100 and display the result.
3. Create a program that prompts the user to input any number and check if it is
both positive and even.
4. Create a program that prompts the user to input any number and check if it is
either negative or zero
5. Create a program that prompts the user to input any number check if it is not a
positive number.