0% found this document useful (0 votes)
27 views9 pages

Python Programming Experiments Guide

The document outlines a series of programming experiments demonstrating various concepts in Python, including variable swapping, finding minimum values, sorting, student marks management, mathematical functions, and data manipulation using libraries like NumPy and Pandas. It also covers search algorithms, matrix operations, and basic file handling. Each experiment is presented with code snippets and explanations of their functionality.

Uploaded by

priyanka62928
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views9 pages

Python Programming Experiments Guide

The document outlines a series of programming experiments demonstrating various concepts in Python, including variable swapping, finding minimum values, sorting, student marks management, mathematical functions, and data manipulation using libraries like NumPy and Pandas. It also covers search algorithms, matrix operations, and basic file handling. Each experiment is presented with code snippets and explanations of their functionality.

Uploaded by

priyanka62928
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Experiment 1:

#eg 1

a,b=10,20

a=a+b

b=a-b

a=a-b

print("method 1:",a,b)

#eg 2

a,b=10,20

temp=a

a=b

b=temp

print("method 2:",a,b)

#eg 3

a,b=10,20

a,b=b,a

print("method 3:",a,b)

Experiment 2:

numbers=list(map(int,input("Enter multiple integers seperated by space:").split()))

print(numbers)

min_value=min(numbers)

print("The minimum value in the list is :",min_value)

#hjghu

numbers=[23,11,78,5,90]

print("Minimum value",min(numbers))
#fcgf

min_val=numbers[0]

for num in numbers:

if num<min_val:

min_val=num

print("Minimum value",min_val)

#fgy

sorted_nums=sorted(numbers)

print("Minimum value",sorted_nums[0])

Experiment 3:

numbers=list(map(int,input("integers:").split()))

print(numbers)

[Link]()

print("ascending order ",numbers)

[Link](reverse=True)

print("descending order",numbers)

Experiment 4:

subject=["DIGITAL LOGIC FUNDEMRNTAL","IT ESSENTIAL","HERBAL


NUTRITION","ENGLISH","UNDERSTANDING INDIA","ENVIRONMENTAL STUDIES"]

subcode=["DLF101","IT102","HN103","ENG104","UI105","EVS106"]

internalmarks=[]

semestermarks=[]

count=Mtotal=0

name=input("Enter name:")

fname=input("Enter father name")

rnumber=int(input("Enter roll number:"))


college=input("Enter college name")

for x in subject:

a=int(input(f"Enter Internal marks for ({x}):"))

b=int(input(f"Enter Semester marks for ({x}):"))

[Link](a)

[Link](b)

print("\n\t\t*********YOUR RESULT**********\n\n\n\n\t")

print(f"\t\t COLLEGE:{college}")

print(f"\t\t ROLL NUMBER: {rnumber}")

print(f"\t\t NAME:{name} \t\t Father name:{fname}\n")

print("\t\t SUBJECT \t\t INTERVAL \t SEMESTER \t TOTAL")

for x,y,z in zip(subcode,internalmarks,semestermarks):

total_marks=y+z

Mtotal +=total_marks

print(f"\t\t{x}\t\t{y}\t\t{z}\t\t{total_marks}")

if total_marks<40:

count+=1

if count==0:

print(f"\n\t\tTOTAL MARKS:{Mtotal}\t\tresult:pass")

else:

print(f"\n\t\t TOTAL MARKS:{Mtotal}\t\tresult:fail")

Experiment 5:

def newton_sqrt(n,tolerance =1e-10):

x=n/2.0

while abs(x*x-n)>tolerance:

x=0.5*(x+n/x)
return x

def gcd(a,b):

while b!=0:

a,b=b,a%b

return a

def fast_power(base,exp):

result=1

while exp>0:

if exp%2==1:

result*=base

base*=base

exp//=2

return result

print("Square root of 25:",newton_sqrt(25))

print("GCD of 56 and 98:",gcd(56,98))

print("2^10:",fast_power(2,10))

Experiment 6:

import numpy as np

arr=[10,20,30,40,50]

s1=0

for num in arr:

s1+=num

s2,i=0,0

while i<len(arr):

s2+=arr[i]

i+=1
s3=sum(arr)

s4=[Link](arr)

print("sum using for loop:",s1)

print("sum using while loop:",s2)

print("sum usinf sum():",s3)

print("sum using numpy:",s4)

Experiment 7a:

def linear_search(lst,x):

for i in range(len(lst)):

if lst[i]==x:

return i

return -1

n=int(input("enter the size of the list:"))

lst=[]

for i in range(n):

[Link](int(input(f"enter element{i+1}:")))

x=int(input("enter the number to search:"))

position=linear_search(lst,x)

if position !=-1:

print(f"entered number{x} is present at position:{position+1}")

else:

print(f"entered number{x} is not present in the list.")

Experiment 7b:

def binary_search(lst,n,x):

start=0

end=n-1

while start<=end:
mid=(start+end)//2

if x==lst[mid]:

return mid

elif x<lst[mid]:

end=mid-1

else:

start=mid+1

return -1

n=int(input("enter the size of the list:"))

lst=[]

for i in range(n):

[Link](int(input(f"enter element{i+1}:")))

x=int(input("enter the number to search:"))

[Link]()

position=binary_search(lst,n,x)

if position !=-1:

print(f"entered number{x} is present at position:{position+1}")

else:

print(f"entered number{x} is not present in the list")

Experiment 8:

import numpy as np

A=[Link]([[1,2,3],[4,5,6],[7,8,0]])

B=[Link]([[9,8,7],[6,5,4],[3,2,1]])

print("matrix A:\n",A)

print("matrix B:\n",B)

add_result=A+B

print("\n matrix addition (A+B):",add_result)


sub_result=A-B

print("\n matrix subraction (A-B):\n",sub_result)

mul_reslut=[Link](A,B)

print("\n matrix multiplication (AXB):",mul_result)

transpose_A=A.T

print("\n transpose of matrix A:\n",transpose_A)

Experiment 9:

import pandas as pd

data={'Name':['Alice','Bob','Charlie','David','Eva'],

'Age':[24,27,22,32,29],

'Marks':[85,90,75,88,95]}

df=[Link](data)

print("original data frame:\n",df)

print("\n first 3 rows:\n",[Link](3))

print("\n info about dataframe:")

print([Link]())

print("\n Access 'Name' columns ;\n",df[Name])

print("\n Access first row :\n",[Link][0])

print("\n Access row with index 2 using loc:\n",[Link][2])

print("\n access row with index 2 using loc:\n",[Link][2])

df['Grade']=['B','A','C','B','A']

print("\n After adding grade column :\n",df)

df['Madras']=df['Madras']+5

print("\n After deleting age column :\n",df)

df=[Link]('Age',axis=1)

print("\n After deleting age column:\n",df)

filtered_df=df[df['Marks']>90]
Experiment 10:

import pandas as pd

import [Link] as plt

data={'student':['Alice','Bob','Charlie','David','Eva'],

'Maths':[85,90,75,88,95],

'Science':[80,92,70,85,98]}

df=[Link](data)

print("dataset:\n",df)

[Link](df['Student'],df['Maths'],marker='0',label='Maths')

[Link](df['Student'],df['Science'],marker='s',label='Science')

[Link]("Line chart-student marks")

[Link]("Student")

[Link]("Marks")

[Link]()

[Link]()

[Link](df['Student'],df['Maths'],color='skyblue',label='Maths')

[Link](df['Student'],df['Science'],bottom=df['Maths'],color='lightgreen',label='Science')

[Link]("Bar chart-student marks")

[Link]("Students")

[Link]("Marks")

[Link]()

[Link](df['Maths'],df['Science'],color='red')

[Link]("scatter plot-maths vs science marks")

[Link]("maths marks")

[Link]("science marks")

[Link]()
Experiment 11a:

with open("[Link]","w")as f:

[Link]("python is a powerful programming [Link] is easy to learn.")

with open("[Link]","r")as f:

text=[Link]()

words=[Link]()

print("file content:\n",text)

print("\n total word count:",len(words))

Experiment 11b:

with open("[Link]","r")as source:

content=[Link]()

with open("copy_sample.txt","w")as dest:

[Link](content)

print("file copied successfully.")

You might also like