0% found this document useful (0 votes)
9 views2 pages

TP1 PYTHON ING 24_25(1) (2)

Uploaded by

bedairiainel
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)
9 views2 pages

TP1 PYTHON ING 24_25(1) (2)

Uploaded by

bedairiainel
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/ 2

Electronic Department

ING RSI
LAB work 1
Exploring Different Types of Operators in Python

Objectives:
 Understand the functionality of different types of operators in Python.
 Apply arithmetic, logical, comparison, bitwise, and assignment operators to solve problems.

Reminder:
Python provides the following arithmetic operators:

arithmetic Comparison Logical Bitwise Assignment Ternary


operators Operators Operators Operators Operators Operator
+ (addition) == (equal) and & (bitwise = (assign) shorthand
- (subtraction) != (not equal) or AND) += (add and for if-else
* > (greater not | (bitwise assign)
(multiplication) than) OR) -= (subtract and
/ (division) < (less than) ^ (bitwise assign)
% (modulus) >= (greater XOR) *= (multiply and
** than or equal ~ (bitwise assign)
(exponentiation) to) NOT) /= (divide and
//(floor division) <= (less than << (left shift) assign)
or equal to) >> (right %= (modulus and
shift) assign)
**= (exponent
and assign)
//= (floor divide
and assign)

Work to do:
The work consists of 6 exercises.
Exercise 1: Write a Python program to:
 Take two integer inputs from the user.
 Perform all the arithmetic operations listed above on these two numbers.
 Print the results of each operation.

Exercise 2: Write a Python program that:


 Takes two inputs from the user.
 Uses all comparison operators to compare these two numbers.
 Prints the result of each comparison.

Exercise 3: Write a Python program that:


 Takes two boolean values as inputs.
 Demonstrates the use of and, or, and not operators on these values.

1/2
Exercise 4: Write a Python program that:
 Takes two integers as input.
 Demonstrates all the bitwise operations on them. (for shift operations, use a step of 2)

Exercise 5: Write a Python program that:


 Initializes a variable x with a value.
 Uses all assignment operators to modify x and prints the result after each operation.

Exercise 6: Write a program that:

 Takes two numbers from the user.


 Uses the ternary operator to find and print the larger of the two numbers.

(ternary operator: [true_condition] if [expression] else [false_condition])

2/2

You might also like