Khwaja Moinuddin Chishti Language University
Khwaja Moinuddin Chishti Language University
INDEX
Sr. Experiment Name Signature Page No.
No
.
1 Install and configure Python IDE.
Write simple Python program to display
2
message on screen
Write simple Python program using operators:
3 a) Arithmetic Operators, b) Logical Operators
and c) Bitwise Operators
Write simple Python program to demonstrate
use of conditional statements:
4
a) ‘if’ statement, b) ‘if … else’ statement and c)
Nested ‘if’ statement
Write Python program to demonstrate use of
looping statements:
5
a) ‘while’ loop b) ‘for’ loop and c) Nested
loops
Write Python program to perform following
operations on Lists:
6
a) Create list, b) Access list, c) Update list (Add
item, remove item) and d) Delete list
Write Python program to perform following
operations on Tuples:
7
a) Create Tuple, b) Access Tuple, c) Update
Tuple and d) Delete Tuple
Write Python program to perform following
operations on Set
8
a) Create Set, b) Access Set elements, c)
Update Set and d) Delete Set
Write Python program to perform following
operations on Dictionaries:
9 a) Create Dictionary, b) Access Dictionary
elements, c) Update Dictionary, d) Delete Set
and e) Looping through Dictionary
3
Source code:
Print (‘hello world’)
Output:
10
Experiment 3
a) Arithmetic Operators
Source code:
a = int(input("enter first number:"))
sum = a + b # Addition
print("sum:", sum)
sub = a – b #Subtraction
print("sub:", sub)
mul = a * b # Multiplication
print("mul:", mul)
div = a / b # Division
print("div:", div)
mod = a % b # Modulus
print("mod:", mod)
floor = a//b # Floor Division
print(“floor:”, floor)
exp = a**b # Exponent
print(“exp:”, exp)
Output:
11
b) Logical Operators
Source code:
a = 12 #Logical AND
b = 26
c=4
if a > b and a > c:
print("Number a is larger")
if b > a and b > c:
print("Number b is larger")
if c > a and c > b:
print("Number c is larger")
Output:
12
a = 10 # Logical OR
b = -5
if a < 0 or b < 0:
print("Their product will be negative")
else:
print("Their product will be positive")
Output:
a = 10 # Logical NOT
if not a == 10:
print ("a not equals 10")
else:
print("a equals 10")
Output:
c) Bitwise Operators
Source code:
a = 10
b=4
# Print bitwise AND operation
print("a & b =", a & b)
# Print bitwise OR operation
print("a | b =", a | b)
# Print bitwise NOT operation
print("~a =", ~a)
# print bitwise XOR operation
print("a ^ b =", a ^ b)
13
Output:
Experiment 4
a) ‘if’ statement:
Source code:
num = 3
if num > 0:
print(“num, is a positive number.”)
print(“This is always printed.”)
num = -1
if num > 0:
print(“num, is a positive number.”)
print(“This is also always printed.”)
Output:
14
b) ‘if…else’ statement
Source code:
num = 3
if num>= 0:
print(“positive or zero”)
else:
print(“print negative number”)
Output:
Output:
15
EXPERIMENT 5
a) ‘while’ loop
Source code:
n = 10
sum = 0
i=1
while i <= n:
sum = sum + i
i=i+1
print (“The sum is ”, sum)
Output:
b) ‘for’ loop
Source code:
numbers = [6, 5, 3, 8, 4, 2, 5, 4, 11]
sum = 0 # variable to store the sum
for val in numbers: # iterate over the sum
sum = sum + val
print (“The sum is”, sum)
16
Output:
c) Nested loop
Source code:
# nested for loop
for i in range(1, 5):
for j in range(i):
print(i, end=' ')
print()
Output:
Output:
18
19
20
21
22
23
24
25
26
27
28
29
30