You are on page 1of 35

Mohammad Alfaiz Khan

21100BTCMCI10079
Experiment-1
Objective: Write down the Installation of Python
Theory:
Python is a popular high-level, general-use programming language. Python is a
programming language that enables rapid development as well as more effective
system integration. Python has two main different versions: Python 2 and Python 3.
Both are really different.
Python develops new versions with changes periodically and releases them
according to version numbers. Python is currently at version 3.12.0.
Installation of Python
Visit the link https://www.python.org to download the latest release of Python.
In this process, I will install Python 3.11.3 on my Windows operating system.
When I visit on the above link, it will bring me to the following page.

Step - 1: Select the Python's version to download.


Click on the download button to download the exe file of Python.
Mohammad Alfaiz Khan
21100BTCMCI10079

If in case you want to download the specific version of Python. Then, you can
scroll down further below to see different versions from 2 and 3 respectively. Click
on download button right next to the version number you want to download.

Step - 2: Click on the Install Now


Double-click the executable file, which is downloaded.
Mohammad Alfaiz Khan
21100BTCMCI10079

The following window will open. Click on the Add Path check box, it will set the
Python path automatically.
Now, Select Customize installation and proceed. We can also click on the
customize installation to choose desired location and features. Other important
thing is install launcher for the all user must be checked.
Here, under the advanced options, click on the checkboxes of " Install Python 3.11
for all users ", which is previously not checked in. This will checks the other option
" Precompile standard library " automatically. And the location of the installation
will also be changed. We can change it later, so we leave the install location
default. Then, click on the install button to finally install.
Mohammad Alfaiz Khan
21100BTCMCI10079

Step - 3 Installation in Process

The set up is in progress. All the python libraries, packages, and other python
default files will be installed in our system. Once the installation is successful, the
following page will appear saying " Setup was successful ".
Mohammad Alfaiz Khan
21100BTCMCI10079

Step - 4: Verifying the Python Installation


To verify whether the python is installed or not in our system, we have to do the
following.
o Go to "Start" button, and search " cmd ".

o Then type, " python - - version ". o If python is successfully installed, then
we can see the version of the python installed. o If not installed, then it will
print the error as " 'python' is not recognized as an internal or external
command, operable program or batch file. "

We are ready to work with the Python.


Mohammad Alfaiz Khan
21100BTCMCI10079
Experiment-2
Objective: Write a program to print any string using python.
Program:
x="Hello"
print(x,"World")
Output:

Experiment-3
Objective: Write a program to add 2 numbers using python
Program:
a = int(input(“Enter first number: ”))
b = int(input(“Enter second number: ”))
print(“Addition of two numbers is”, a+b)
Output:
Mohammad Alfaiz Khan
21100BTCMCI10079
Experiment-4
Objective: Write a program to find maximum of two numbers using python.
Program:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a>b:
print(a," is greater then ",b)
else:
print(b," is greater then ",a)
Output:

Experiment-5
Objective: Write a program to find factorial of
any number
Program:
a = int(input("Enter any number: "))
fact = 1
for i in range (a,0,-1):
fact = fact* i
Mohammad Alfaiz Khan
21100BTCMCI10079
print(fact)
Output:

Experiment-6
Objective: Write a program to find simple interest using python
Program:
P=int(input("Enter Principle Amount : "))
R=int(input("Enter Rate Amount : "))
T=int(input("Enter Time Duration : "))
SI = (P*R*T)/100
print("Simple Interest = ",SI)
Output:
Mohammad Alfaiz Khan
21100BTCMCI10079
Experiment-7
Objective: Write a program to calculate area of circle
Program:
from numpy import pi
r = int(input("Enter radius of circle: "))
print("Area of Circle = ", pi*(r**2))
Output:

Experiment-8
Objective: Write a program to check Armstrong Number.
Program:
num = int(input("Enter any number: "))
sum = 0
new = num
dis = len(str(num))
while(num>0):
a = num%10
sum+= a**dis
num = num//10
print("Output is : ",sum)
Mohammad Alfaiz Khan
21100BTCMCI10079
if(new == sum):
print("The number is Armstrong")
else:
print("Not an Armstrong number ")
Output:

Experiment-9
Objective: Write a program to check whether a number
is prime or not.
Program:
a=int(input("Enter any number: "))
i=2
if(a==1):
print("Neither Prime nor Composite Number")
elif(a%i==0):
i+=1
print("Not a Prime Number : ",a)
else:
Mohammad Alfaiz Khan
21100BTCMCI10079
print("Prime number : ",a)
Output:

Experiment-10
Objective: Write a program to print Fibonacci
series
Program:
a = int(input("Enter any number : "))
x=0
y=1
z=0
while(a>=z):
print(z)
x=y
y=z
z=x+y
Output:
Mohammad Alfaiz Khan
21100BTCMCI10079

Experiment-11
Objective: Write a program to print ascii value of characters.
Program:
a = input("Enter any Character: ")
print("ASCII value of Character is : ",ord(a))
Output:

Experiment-12
Objective: Write a program to make a Calculator using Operators.
Program:
while True:
Mohammad Alfaiz Khan
21100BTCMCI10079
t = input("Enter TRUE if you want to continue the Operations Otherwise Enter
FALSE :")
if t.lower() in ["true", "t"]:
print("Press 1 For Arithmetic operator\nPress 2 For Assignment operator\
nPress 3 For Comparison operator\nPress 4 For Logical operator\nPress 5 For
Identity operator\nPress 6 For Bitwise operator\n")
x = int(input("Enter number: "))
if x == 1:
print("Press 1 for Addition\nPress 2 for Subtraction\nPress 3 for
Multiplication\nPress 4 for Division\nPress 5 for Modulus\nPress 6 for
Exponentiation\nPress 7 for Floor Division\n")
y = int(input("Enter Selected case number: "))
a = int(input("Enter First Number: "))
b = int(input("Enter Second Number: "))
if y == 1:
print("Addition of two numbers is: ", a + b)
elif y == 2:
print("Subtraction of two numbers is: ", a - b)
elif y == 3:
print("Multiplication of two numbers is: ", a * b)
elif y == 4:
print("Division of two numbers is: ", a / b)
elif y == 5:
print("Modulus of two numbers is: ", a % b)
Mohammad Alfaiz Khan
21100BTCMCI10079
elif y == 6:
print("Exponentiation of two numbers is: ", a ** b)
elif y == 7:
print("Floor Division of two numbers is: ", a // b)
elif x == 2:
print("Press 1 for =\nPress 2 for +=\nPress 3 for -=\nPress 4 for =\nPress 5
for =\nPress 6 for %=\nPress 7 for //=\nPress 8 for *=\nPress 9 for &= \nPress 10
for |=\nPress 11 for ^=\nPress 12 for >>=\nPress 13 for <<=\n")
y = int(input("Enter Selected case number: "))
a = int(input("Enter Number: "))
b = int(input("Enter Second Number: "))
if y == 1:
print(a)
elif y == 2:
a += b
print(a)
elif y == 3:
a -= b
print(a)
elif y == 4:
a *= b
print(a)
elif y == 5:
a /= b
Mohammad Alfaiz Khan
21100BTCMCI10079
print(a)
elif y == 6:
a %= b
print(a)
elif y == 7:
a //= b
print(a)
elif y == 8:
a **= b
print(a)
elif y == 9:
a &= b
print(a)
elif y == 10:
a |= b
print(a)
elif y == 11:
a ^= b
print(a)
elif y == 12:
a >>= b
print(a)
elif y == 13:
a <<= b
Mohammad Alfaiz Khan
21100BTCMCI10079
print(a)
elif x == 3:
print("Press 1 for =\nPress 2 for !=\nPress 3 for >\nPress 4 for <\nPress 5
for >=\nPress 6 for <=\n")
y = int(input("Enter Selected case number: "))
a = int(input("Enter First Number: "))
b = int(input("Enter Second Number: "))
if y == 1:
print(a == b)
elif y == 2:
print(a != b)
elif y == 3:
print(a > b)
elif y == 4:
print(a < b)
elif y == 5:
print(a >= b)
elif y == 6:
print(a <= b)
elif x == 4:
print("Press 1 for AND\nPress 2 for OR\nPress 3 for NOT\n")
y = int(input("Enter Selected case number: "))
a = int(input("Enter First Number: "))
b = int(input("Enter Second Number: "))
Mohammad Alfaiz Khan
21100BTCMCI10079
if y == 1:
print("a<1 AND b<1\nIF BOTH CONDITIONS ARE TRUE THEN IT
WILL PRINT TRUE\n", a < 1 and b < 1)
elif y == 2:
print("a<1 AND b<1\nIF ANY ONE CONDITION IS TRUE THEN IT
WILL PRINT TRUE\n", a < 1 or b < 1)
elif y == 3:
print("a is not equal to b: ", a != b)
elif x == 5:
len1 = int(input("Enter length of list1: "))
l1 = []
for i in range(len1):
x = input("Enter items to append in list1: ")
l1.append(x)
print(l1)
len2 = int(input("Enter length of list2: "))
l2 = []
for i in range(len2):
x = input("Enter items to append in list2: ")
l2.append(x)
print(l2)
print("Press 1 for IS\nPress 2 for IS NOT\n")
y = int(input("Enter Selected case number: "))
if y == 1:
Mohammad Alfaiz Khan
21100BTCMCI10079
print("IT WILL PRINT TRUE IF L1 IS THE SAME OBJECT AS L2: ",
l1 is l2)
print("IT WILL PRINT FALSE IF L1 IS NOT THE SAME OBJECT AS
L2 EVEN IF THEY HAVE THE SAME CONTENT : ", l1 is not l2)
print("IT WILL PRINT TRUE IF L1 == L2 : ", l1 == l2)
elif y == 2:
print("IT WILL PRINT FALSE IF L1 IS THE SAME OBJECT AS L2: ",
l1 is not l2)
print("IT WILL PRINT TRUE IF L1 IS NOT THE SAME OBJECT AS
L2 EVEN IF THEY HAVE THE SAME CONTENT : ", l1 is not l2)
print("IT WILL PRINT FALSE BECAUSE L1 IS EQUAL TO L2 : ",
l1 != l2)
elif x == 6:
print("Press 1 for AND\nPress 2 for OR\nPress 3 for XOR\nPress 4 for
NOT\nPress 5 for ZERO FILL LEFT SHIFT\nPress 6 for SIGNED RIGHT
SHIFT\n")
y = int(input("Enter Selected case number: "))
a = int(input("Enter Number: "))
b = int(input("Enter Second Number: "))
if y == 1:
print(a & b)
elif y == 2:
print(a | b)
elif y == 3:
Mohammad Alfaiz Khan
21100BTCMCI10079
print(a ^ b)
elif y == 4:
print("For not a: ", ~a)
print("For not b: ", ~b)
elif y == 5:
print("LEFT \na is shifted by b: ", a << b)
elif y == 6:
print("RIGHT \na is shifted by b: ", a >> b)
else:
print("THANK YOU")
Output:
Mohammad Alfaiz Khan
21100BTCMCI10079

Experiment-13
Objective: Write a program to print f string in python
Program:
name= input("Enter your name = ")
Age = int(input("Enter your age = "))
height = float(input("Enter your height = "))
print("_")
print(f"My name is {name} \nI am {Age} years old \nHeight = {height}")
Output:
Mohammad Alfaiz Khan
21100BTCMCI10079

Experiment-14
Objective: Write a program to implement round of function in python
Program:
while True:
n = eval(input("Enter any number: "))
value = int(input("Enter number of digits to be round off: "))
print(round(n))
print(round(n,value))
Output:
Mohammad Alfaiz Khan
21100BTCMCI10079
Experiment-15
Objective: Write a program to Perform tuples and its operations
Program:
tup1=(1,'Alfaiz','CSE')
tup2=(2,'Faiz','IT')
print(tup1)
print(tup2)
print(type(tup1))
print("----------------------------")
# Accessing items
print(tup1[2])
print(tup2[1][2])
print(tup2[1][3])
# Concatenation
print("------Concatenation------")
print(tup1+tup2)
print("----------------------------")
#Getting Input From User
sno = int(input("Enter any number :"))
name = input("Enter any name: ")
input = (sno,name)
print(input)
print("------------------------------")
Mohammad Alfaiz Khan
21100BTCMCI10079
#Nesting
print("Nesting Operation on Tuples")
tup3 = (tup1,tup2)
print(tup3)
print("------------------------------")
#Slicing Operation
print("Slicing Operation on Tuples")
tup4 = (100,'Alfaiz', 'Khan','CMC')
print("Slicing: ",tup4[1:3])
print("-------------------------------------------
---")
#Finding Length
print("Finding length of Tuples")
print("Length of tup4 : ",len(tup4))
print("----------------------------------------")
#Deleting is not possible
print("Deleting a Tuple")
tup5 = (101,"Alfaiz",102,"Faiz")
del(tup5[1])
print(tup5)
print("---------------------------------------")
#Membership
print("Membership Test on Tuples")
tup6= (1,"East")
Mohammad Alfaiz Khan
21100BTCMCI10079
print( 1 in tup6)
print("--------------------------------------")
Output:

Experiment-16
Objective: Write a python program to create and perform List Operation
Program:
List = [1,"Alfaiz", "CSE"]
print("List = ",List)
print(type(List))

#ADD ITEMS IN LIST


Mohammad Alfaiz Khan
21100BTCMCI10079
List3 = [1,2,3,4,5]
List3+=(6,)
print(List3)

List4 = [10,20,30,40,50,60,70,80,90]
print("Program to get the 4th element from the last element of the list ",List4[4])

List8 = [101,102,103,104,105,106]
List9 = [107,108,109,110]
List10 = List8+ List9
print("Concatenating the two lists = ",List10)

List11=[344,346,654,325,656]
print("Max element in the list = ",max(List11))
print("Min element in the list = ",min(List11))

List12= ["Faiz","Aateef","Manoj"]
List12.append("Ishaan")
print("After append : ",List12)
List12.pop()
print("After pop : ",List12)

List13=[3,5,6,9,1,2]
print("Sorted List = ",sorted(List13))
Mohammad Alfaiz Khan
21100BTCMCI10079

List14= [77,85,55,60,54]
for i in List14:
if i%5==0:
print(i)
Output:

Experiment-17
Objective: Write a python program to create and perfrom Dictionary operation
Program:
Dict = {'Name': 'Alfaiz','Age': 19,'Program':'B.Tech.','Branch':'CSE-CMC','City':
'Indore'}
print(Dict)
print(type(Dict))

# to fetch only keys in dictionary.


Mohammad Alfaiz Khan
21100BTCMCI10079
Dict0 = {'Name': 'Alfaiz','Age': 19,'Program':'B.Tech.','Branch':'CSE-CMC','City':
'Indore'}
print(Dict0.keys())

# to fetch only values in dictionary.


Dict00 = {'Name': 'Alfaiz','Age': 19,'Program':'B.Tech.','Branch':'CSE-CMC','City':
'Indore'}
print(Dict00.values())

# to add a new element in dictionary


Dict01 = {'Name': 'Alfaiz','Age': 19,'Program':'B.Tech.','Branch':'CSE-CMC','City':
'Indore'}
Dict01.update({'Year':2})
print("After updation ",Dict01)

# Program to change an existing element in dictionary


Dict1 = {'Name': 'Alfaiz','Age': 19,'Program':'B.Tech.','Branch':'CSE-CMC','City':
'Indore'}
Dict1['Age']=19
print(Dict1)

# Program to add a dictionary into existing dictionary


Dict1 = {'Car name': 'Verna','Engine':1.6}
Dict2 = {'Company name': 'Hyundai'}
Mohammad Alfaiz Khan
21100BTCMCI10079
Dict1.update(Dict2)
print(Dict1)

# Program to pop an element from dictionary and print the dictionary


Dict3 = {'Name': 'Faiz','Age':19,'Program':'B.Tech.','Branch':'CSE-
CMC','City':'Indore'}
Dict3.pop('City')
print("After pop ",Dict3)

# Sort the dictionary by ascending and descending.


Dict4 = {'Name':'Faiz','Age':19,'Program':'B.Tech.','Branch':'CSE-
CMC','City':'Indore'}
print("After Sorting in Ascending Order ",sorted(Dict4))
print("After Sorting in Descending Order ",sorted(Dict4,reverse=True))

# Program to sum all the values of the dictionary.


Dict5 = {'Book':20,'Cost Price':900,'Sell Price':200}
print("Sum of all the values of the dictionary =",sum(Dict5.values()))
Output:
Mohammad Alfaiz Khan
21100BTCMCI10079

Experiment-18
Objective: Write a python program to create and perform Set Operation
Program:
# to Create a set and return the size of the set
Set = {'Alfaiz',20,100000000,'CSE','M'}
print(Set)
print(len(Set))
print("--------------------------------------------------------")

# to Return a new set of Identical items from two sets


Set = {'Alfaiz',20,100000000,'CSE','M'}
Set1 = {'Alfaiz',20,100000000,'CSE','Indore'}
print(Set.intersection(Set1))
print("---------------------------------------------------------")

# to Add elements to a set


Mohammad Alfaiz Khan
21100BTCMCI10079
Set = {'Faiz',20,100000000,'CSE', 'A'}
Set.add('Ujjain')
print(Set)
print("-------------------------------------------")

# to Get only unique items from two sets


Set = {'Alfaiz',20,100000000,'CSE','M','B+'}
Set1 = {'Alfiaz',20,100000000,'CSE', 'Indore'}
print((Set.difference(Set1)).union(Set1.difference(Set)))
print("---------------------------------------------")

# to Get elements that are only in combined set B Set =


{'Raghav',20,100000000,'CSE','A','O+'}
Set1 = {'Alfaiz',20,100000000,'CSE','Indore'}
A = Set.union(Set1)
print(A)
print(A.intersection(Set1))
print("---------------------------------------------------")

# to Program to create a union of sets


Set = {'Alfaiz',20,100000000,'CSE','M','B+'}
Set1 = {'Alfaiz',20,100000000,'CSE','Indore'}
print(Set.union(Set1))
print("----------------------------------------------------")
Mohammad Alfaiz Khan
21100BTCMCI10079

# to Check in set A and set B which set is a subset of another set


Set = {'Alfaiz',20,100000000,'CSE','M','B+'}
Set1 = {'Alfaiz',100000000,'CSE'}
print(Set1.issubset(Set))
print(Set.issubset(Set1))
print("---------------------------------------")
# to Convert set into dictionary
Set = {'Alfaiz',20,100000000,'CSE','M'}
C = dict.fromkeys(Set,0)
print(C)
print("-----------------------------------------")
# to convert set into tuple
Set = {'Alfaiz',20,100000000,'CSE','M'}
print(tuple(Set))
print("------------------------------------------")
# to Remove element from a set using pop, discard and remove methods
Set = {'Alfaiz',20,100000000,'CSE','M'}
Set.discard(20)
print(Set)
Set.remove('A')
print(Set)
Set.pop()
print(Set)
Mohammad Alfaiz Khan
21100BTCMCI10079
print("--------------------------------------------")
Output:

Experiment-19
Objective: Write a python program to perform Toggle operation.
Program:
class A:
def toggle(self,s1=""):
s1 = input("Enter any String:")
self.s1=s1
s=s1.split()
for word in s:
if word.islower():
print(word.upper(),end = "")
Mohammad Alfaiz Khan
21100BTCMCI10079
elif word.isupper():
print(word.lower(),end = "")
else:
print(word,end="")
obj = A()
obj.toggle()
Output:

Experiment-20
Objective: Write a python program to give grade on basis of marks using if elif.
Program:
print("Please enter marks between 1 to 100")
physics = int(input("Enter Physics Marks of Students: "))
chemistry = int(input("Enter Chemistry Marks of Students: "))
maths = int(input("Enter maths Marks of Students: "))
per = (physics + chemistry + maths)/3
if per>=90:
print("Percentage = ",per)
print("GRADE O")
Mohammad Alfaiz Khan
21100BTCMCI10079
elif per>=80 and per<90:
print("Percentage = ",per)
print("GRADE A")
elif per<80 and per>=70:
print("Percentage = ",per)
print("GRADE B")
elif per<70 and per>=60:
print("Percentage = ",per)
print("GRADE C")
elif per<60 and per>=50:
print("Percentage = ",per)
print("GRADE D")
elif per<50 and per>=40:
print("Percentage = ",per)
print("GRADE E")
else:
print("Percentage = ",per)
print("Fail")
Output:
Mohammad Alfaiz Khan
21100BTCMCI10079

You might also like