0% found this document useful (0 votes)
5 views8 pages

Practical 3,4,5

The document contains practical exercises on arithmetic, logical, and bitwise operators in Python, demonstrating their usage with examples. It also includes control flow statements such as if, if-else, and nested if statements, as well as loops including while and for loops. Each section provides code snippets along with expected outputs for better understanding.

Uploaded by

Priti Mane
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)
5 views8 pages

Practical 3,4,5

The document contains practical exercises on arithmetic, logical, and bitwise operators in Python, demonstrating their usage with examples. It also includes control flow statements such as if, if-else, and nested if statements, as well as loops including while and for loops. Each section provides code snippets along with expected outputs for better understanding.

Uploaded by

Priti Mane
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/ 8

Practical No:03

Name: Shinde Siddhi Babasaheb Roll No:24/36-050


Batch:C

Arithmetic Operators

num1 = 10 num2 = 3 #

Addition addition = num1


+ num2 print("Addition:",

addition)

# Subtraction subtraction =

num1 - num2
print("Subtraction:", subtraction)

# Multiplication multiplication =
num1 * num2 print("Multiplication:",
multiplication)

# Division division =
num1 / num2
print("Division:", division)

# Floor Division floor_division =

num1 // num2 print("Floor Division:",


floor_division)

# Modulus modulus =
num1 % num2
print("Modulus:", modulus)

# Exponentiation
exponentiation = num1 **

num2

print("Exponentiation:",
exponentiation)

Output:

Logical Operators
# Define two boolean variables
a = True b = False

# Logical AND and_result = a and

b print("Logical AND:",
and_result)

# Logical OR or_result = a or
b

print("Logical OR:", or_result)


# Logical NOT not_result_a
= not a not_result_b = not b

print("Logical NOT of a:", not_result_a)


print("Logical NOT of b:", not_result_b) Output:

Bitwise Operators

# Define two numbers


a = 10 b = 4

# Bitwise AND and_result = a &

b print("Bitwise AND:",
and_result)

# Bitwise OR

or_result = a | b

print("Bitwise OR:", or_result)

# Bitwise XOR xor_result = a ^ b

print("Bitwise XOR:", xor_result)

# Bitwise NOT not_result_a


= ~a not_result_b = ~b
print("Bitwise NOT of a:", not_result_a)

print("Bitwise NOT of b:", not_result_b) # Bitwise


left shift left_shift_a = a << 1 left_shift_b = b << 1

print("Bitwise left shift of a by 1:", left_shift_a)


print("Bitwise left shift of b by 1:", left_shift_b)

# Bitwise right shift right_shift_a = a >> 1


right_shift_b = b >> 1 print("Bitwise right shift of
a by 1:", right_shift_a) print("Bitwise right shift of
b by 1:", right_shift_b)

Output:
Practical No:04
Name: Shinde Siddhi Babasaheb Roll No:24/36-050
Batch:C

if Statement
if 10 > 5: print("10
greater than 5")

print("Program ended")

Output:

If…..else Statement

x = 3 if x ==

4:
print("Yes")

else:
print("No")

Output:
Nested if Statement

num = 15 if num > 10:


print("Number is greater than 10.")
if num % 2 == 0:

print("Number is even.")
else: print("Number
is odd.") Output:
Practical No:05
Name: Shinde Siddhi Babasaheb Roll No:24/36-050

Batch: C

While Loop
i = 1 while i
<= 5:

print(i)
i += 1

Output:

For Loop

text = "Hello" for

char in text:

print(char)

Output:
Nested Loops

n = 5 for i in range(n):

for j in range(n - i - 1):

print(" ", end="") for k


in range(2 * i + 1):

print("*", end="")
print()

Output:

You might also like