SlideShare a Scribd company logo
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
print("Enter first Number:")
a=int(input())
print("Enter second number: ")
b=int(input())
rem=a%b
while rem!=0:
a=b
b=rem
rem=a%b
print("GCD of given number is:", b)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
Enter first Number:
5
Enter second number:
10
('GCDof given number is:', 5)
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
def newtonSqrt(n):
approx = 0.5 * n
better = 0.5 * (approx + n/approx)
while better != approx:
approx = better
better = 0.5 * (approx + n/approx)
return approx
print('The square root is' ,newtonSqrt(81))
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
('The square root is', 9.0)
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
n = int(input("Enter the number: "))
e = int(input("Enter the expo: "))
r=n
for i in range(1,e):
r=n*r
print("Exponent is :", r)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
Enter the number: 2
Enter the expo: 3
('Exponent is :', 8)
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
alist = [-45,0,3,10,90,5,- 2,4,18,45,100,1,-266,706]
largest = alist[0]
for large in alist:
if large > alist:
largest = large
print(“The Largest Number is:”,largest)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
(‘The Largest of the List is:’, 706)
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
def Linearsearch(alist,item):
pos=0
found=False
stop=False
while pos<len(alist) and not found and not stop:
if alist[pos]==item:
found=True
print("Element found in position",pos)
else:
if alist[pos]>item:
stop=True
else:
pos=pos+1
return found
a=[]
n=int(input("Enter upper limit"))
for i in range(0,n):
e=int(input("Enter the elements"))
a.append(e)
x=int(input("Enter element to search"))
Linearsearch(a,x)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
Enter upper limit:5
Enter the elements:1
Enter the elements:8
Enter the elements:9
Enter the elements:6
Enter the elements:7
Enter element to search:9
Element found in position: 2
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
def binarysearch(a,n,k):
low = 0
high = n
while(low<=high):
mid=int((low+high)/2)
if(k==a[mid]):
return mid
elif(k<a[mid]):
high=mid-1
else:
low=mid+1
return -1
n=int(input("Enter the size of list"))
a=[i for i in range(n)]
print(n)
print("Enter the element")
for i in range(0,n):
a[i]=int(input())
print("Enter the element to be searched")
k=int(input())
position=binarysearch(a,n,k)
if(position!=-1):
print("Entered no:%d is present:%d"%(k,position))
else:
print("Entered no:%d is not present in list"%k)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
Enter the size of list
5
Enter the element
1
8
6
3
4
Enter the element to be searched
1
Entered no:1 is present:0
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
def selectionSort(alist):
for i in range(len(alist)-1,0,-1):
pos=0
for location in range(1,i+1):
if alist[location]>alist[pos]:
pos= location
temp = alist[i]
alist[i] = alist[pos]
alist[pos] = temp
alist = [54,26,93,17,77,31,44,55,20]
selectionSort(alist)
print(alist)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
[17, 20, 26, 31, 44, 54, 55, 77, 93]
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
def insertionSort(alist):
for index in range(1,len(alist)):
currentvalue = alist[index]
position = index
while position>0 and alist[position-1]>currentvalue:
alist[position]=alist[position-1]
position = position-1
alist[position]=currentvalue
alist = [54,26,93,17,77,31,44,55,20]
insertionSort(alist)
print(alist)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
[17, 20, 26, 31, 44, 54, 55, 77, 93]
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
def mergeSort(alist):
print("Splitting ",alist)
if len(alist)>1:
mid = len(alist)//2
lefthalf = alist[:mid]
righthalf = alist[mid:]
mergeSort(lefthalf)
mergeSort(righthalf)
i=0
j=0
k=0
while i < len(lefthalf) and j < len(righthalf):
if lefthalf[i] < righthalf[j]:
alist[k]=lefthalf[i]
i=i+1
else:
alist[k]=righthalf[j]
j=j+1
k=k+1
while i < len(lefthalf):
alist[k]=lefthalf[i]
i=i+1
k=k+1
while j < len(righthalf):
alist[k]=righthalf[j]
j=j+1
k=k+1
print("Merging ",alist)
alist = [23, 6, 4 ,12, 9]
mergeSort(alist)
print(alist)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
('Splitting ', [23, 6, 4, 12, 9])
('Splitting ', [23, 6])
('Splitting ', [23])
('Merging ', [23])
('Splitting ', [6])
('Merging ', [6])
('Merging ', [6, 23])
('Splitting ', [4, 12, 9])
('Splitting ', [4])
('Merging ', [4])
('Splitting ', [12, 9])
('Splitting ', [12])
('Merging ', [12])
('Splitting ', [9])
('Merging ', [9])
('Merging ', [9, 12])
('Merging ', [4, 9, 12])
('Merging ', [4, 6, 9, 12, 23])
[4, 6, 9, 12, 23]
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
i=1
x = int(input("Enter the Upper Limit:"))
for k in range (1, (x+1), 1):
c=0;
for j in range (1, (i+1), 1):
a = i%j
if (a==0):
c = c+1
if (c==2):
print (i)
else:
k = k-1
i=i+1
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
Enter the Upper Limit:100
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
X= [[1,2,7],
[4,5,6],
[1,2,3]]
Y= [[5,8,1],
[6,7,3],
[4,5,1]]
result= [[0,0,0],
[0,0,0],
[0,0,0]]
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j]+=X[i][k]*Y[k][j]
for r in result:
print(r)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
[45, 57, 14]
[74, 97, 25]
[29, 37, 10]
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
import sys
if len(sys.argv)!=2:
print('Error: filename missing')
sys.exit(1)
filename = sys.argv[1]
file = open(filename, "r+")
wordcount={}
for word in file.read().split():
if word not in wordcount:
wordcount[word] = 1
else:
wordcount[word]+=1
for k,v in wordcount.items():
print (k, v)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
filename = input("Enter file name:")
inf = open(filename,'r')
wordcount={}
for word in inf.read().split():
if word not in wordcount:
wordcount[word] = 1
else:
wordcount[word] += 1
for key in wordcount.keys():
print("%sn%sn"%(key, wordcount[key]))
linecount = 0
for i in inf:
paragraphcount = 0
if'n'in i:
linecount += 1
if len(i)<2: paragraphcount *= 0
elif len(i)>2: paragraphcount = paragraphcount + 1
print('%-4dn%4dn%sn'%(paragraphcount,linecount,i))
inf.close()
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
Enter file name:'text.txt'
a
1
used
1
for
1
language
1
Python
1
is
1
programming
2
general-purpose
1
widely
1
high-level
1
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
import pygame
import math
import sys
pygame.init()
screen = pygame.display.set_mode((600, 300))
pygame.display.set_caption("Elliptical orbit")
clock = pygame.time.Clock()
while(True):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
xRadius = 250
yRadius = 100
for degree in range(0,360,10):
x1 = int(math.cos(degree * 2 * math.pi / 360) * xRadius) + 300
y1 = int(math.sin(degree * 2 * math.pi / 360) * yRadius) + 150
screen.fill((0, 0, 0))
pygame.draw.circle(screen, (255, 0, 0), [300, 150], 35)
pygame.draw.ellipse(screen, (255, 255, 255), [50, 50, 500, 200], 1)
pygame.draw.circle(screen, (0, 0, 255), [x1, y1], 15)
pygame.display.flip()
clock.tick(5)
GE 8161 – Problem Solving and Python Programming Laboratory
Output:
GE 8161 – Problem Solving and Python Programming Laboratory
Program:
import pygame,sys,time,random
from pygame.locals import*
from time import*
pygame.init()
windowSurface=pygame.display.set_mode((500,400),0,32)
pygame.display.set_caption("BOUNCE")
BLACK=(0,0,0)
WHITE=(255,255,255)
RED=(255,0,0)
GREEN=(0,255,0)
BLUE=(0,0,255)
info=pygame.display.Info()
sw=info.current_w
sh=info.current_h
y=0
direction=1
while True:
windowSurface.fill(BLACK)
pygame.draw.circle(windowSurface,GREEN,(250,y),13,0)
sleep(.006)
y+=direction
if y>=sh:
direction=-1
elif y<=0:
direction=1
pygame.display.update()
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
GE 8161 – Problem Solving and Python Programming Laboratory
Output:

More Related Content

What's hot

Uncertainty in AI
Uncertainty in AIUncertainty in AI
Uncertainty in AI
Amruth Veerabhadraiah
 
Lect9 Decision tree
Lect9 Decision treeLect9 Decision tree
Lect9 Decision tree
hktripathy
 
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain RatioLecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Marina Santini
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
wahab khan
 
Classification Based Machine Learning Algorithms
Classification Based Machine Learning AlgorithmsClassification Based Machine Learning Algorithms
Classification Based Machine Learning Algorithms
Md. Main Uddin Rony
 
Inductive bias
Inductive biasInductive bias
Inductive bias
swapnac12
 
Multilayer perceptron
Multilayer perceptronMultilayer perceptron
Multilayer perceptron
omaraldabash
 
Machine Learning and its Applications
Machine Learning and its ApplicationsMachine Learning and its Applications
Machine Learning and its Applications
Dr Ganesh Iyer
 
Naive bayes
Naive bayesNaive bayes
Naive bayes
umeskath
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & Reasoning
Sajid Marwat
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
Ashim Lamichhane
 
Machine learning ppt
Machine learning pptMachine learning ppt
Machine learning ppt
Rajat Sharma
 
Artificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesArtificial Intelligence Searching Techniques
Artificial Intelligence Searching Techniques
Dr. C.V. Suresh Babu
 
Uninformed Search technique
Uninformed Search techniqueUninformed Search technique
Uninformed Search technique
Kapil Dahal
 
Radial basis function network ppt bySheetal,Samreen and Dhanashri
Radial basis function network ppt bySheetal,Samreen and DhanashriRadial basis function network ppt bySheetal,Samreen and Dhanashri
Radial basis function network ppt bySheetal,Samreen and Dhanashri
sheetal katkar
 
Feature Extraction
Feature ExtractionFeature Extraction
Feature Extraction
skylian
 
Bayes Belief Networks
Bayes Belief NetworksBayes Belief Networks
Bayes Belief Networks
Sai Kumar Kodam
 
Convolution Neural Network (CNN)
Convolution Neural Network (CNN)Convolution Neural Network (CNN)
Convolution Neural Network (CNN)
Suraj Aavula
 
AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)
Tajim Md. Niamat Ullah Akhund
 
Naive Bayes
Naive BayesNaive Bayes
Naive Bayes
CloudxLab
 

What's hot (20)

Uncertainty in AI
Uncertainty in AIUncertainty in AI
Uncertainty in AI
 
Lect9 Decision tree
Lect9 Decision treeLect9 Decision tree
Lect9 Decision tree
 
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain RatioLecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
 
Classification Based Machine Learning Algorithms
Classification Based Machine Learning AlgorithmsClassification Based Machine Learning Algorithms
Classification Based Machine Learning Algorithms
 
Inductive bias
Inductive biasInductive bias
Inductive bias
 
Multilayer perceptron
Multilayer perceptronMultilayer perceptron
Multilayer perceptron
 
Machine Learning and its Applications
Machine Learning and its ApplicationsMachine Learning and its Applications
Machine Learning and its Applications
 
Naive bayes
Naive bayesNaive bayes
Naive bayes
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & Reasoning
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
 
Machine learning ppt
Machine learning pptMachine learning ppt
Machine learning ppt
 
Artificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesArtificial Intelligence Searching Techniques
Artificial Intelligence Searching Techniques
 
Uninformed Search technique
Uninformed Search techniqueUninformed Search technique
Uninformed Search technique
 
Radial basis function network ppt bySheetal,Samreen and Dhanashri
Radial basis function network ppt bySheetal,Samreen and DhanashriRadial basis function network ppt bySheetal,Samreen and Dhanashri
Radial basis function network ppt bySheetal,Samreen and Dhanashri
 
Feature Extraction
Feature ExtractionFeature Extraction
Feature Extraction
 
Bayes Belief Networks
Bayes Belief NetworksBayes Belief Networks
Bayes Belief Networks
 
Convolution Neural Network (CNN)
Convolution Neural Network (CNN)Convolution Neural Network (CNN)
Convolution Neural Network (CNN)
 
AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)
 
Naive Bayes
Naive BayesNaive Bayes
Naive Bayes
 

Similar to Python Lab manual program for BE First semester (all department

Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
iloveallahsomuch
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
iloveallahsomuch
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
Abdul Haseeb
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
Natarajan Angappan
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
vsssuresh
 
Matlab1
Matlab1Matlab1
Matlab1
guest8ba004
 
Pythonic Math
Pythonic MathPythonic Math
Pythonic Math
Kirby Urner
 
4. functions
4. functions4. functions
4. functions
PhD Research Scholar
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
Dr. Rajdeep Chatterjee
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
g3_nittala
 
Testing for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for TestingTesting for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for Testing
Tao Xie
 
Perm winter school 2014.01.31
Perm winter school 2014.01.31Perm winter school 2014.01.31
Perm winter school 2014.01.31
Vyacheslav Arbuzov
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
Sajid Marwat
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
YekoyeTigabuYeko
 
07012023.pptx
07012023.pptx07012023.pptx
07012023.pptx
NareshBopparathi1
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
Khaled Al-Shamaa
 
Vb scripting
Vb scriptingVb scripting
Vb scripting
Rajanikanth Bandela
 
Advanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdfAdvanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdf
Sheba41
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.ppt
AnishaJ7
 
Sample Exam Questions on Python for revision
Sample Exam Questions on Python for revisionSample Exam Questions on Python for revision
Sample Exam Questions on Python for revision
afsheenfaiq2
 

Similar to Python Lab manual program for BE First semester (all department (20)

Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Matlab1
Matlab1Matlab1
Matlab1
 
Pythonic Math
Pythonic MathPythonic Math
Pythonic Math
 
4. functions
4. functions4. functions
4. functions
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Testing for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for TestingTesting for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for Testing
 
Perm winter school 2014.01.31
Perm winter school 2014.01.31Perm winter school 2014.01.31
Perm winter school 2014.01.31
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
07012023.pptx
07012023.pptx07012023.pptx
07012023.pptx
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Vb scripting
Vb scriptingVb scripting
Vb scripting
 
Advanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdfAdvanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdf
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.ppt
 
Sample Exam Questions on Python for revision
Sample Exam Questions on Python for revisionSample Exam Questions on Python for revision
Sample Exam Questions on Python for revision
 

Recently uploaded

Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 

Recently uploaded (20)

Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 

Python Lab manual program for BE First semester (all department

  • 1. GE 8161 – Problem Solving and Python Programming Laboratory Program: print("Enter first Number:") a=int(input()) print("Enter second number: ") b=int(input()) rem=a%b while rem!=0: a=b b=rem rem=a%b print("GCD of given number is:", b)
  • 2. GE 8161 – Problem Solving and Python Programming Laboratory Output: Enter first Number: 5 Enter second number: 10 ('GCDof given number is:', 5)
  • 3. GE 8161 – Problem Solving and Python Programming Laboratory Program: def newtonSqrt(n): approx = 0.5 * n better = 0.5 * (approx + n/approx) while better != approx: approx = better better = 0.5 * (approx + n/approx) return approx print('The square root is' ,newtonSqrt(81))
  • 4. GE 8161 – Problem Solving and Python Programming Laboratory Output: ('The square root is', 9.0)
  • 5. GE 8161 – Problem Solving and Python Programming Laboratory Program: n = int(input("Enter the number: ")) e = int(input("Enter the expo: ")) r=n for i in range(1,e): r=n*r print("Exponent is :", r)
  • 6. GE 8161 – Problem Solving and Python Programming Laboratory Output: Enter the number: 2 Enter the expo: 3 ('Exponent is :', 8)
  • 7. GE 8161 – Problem Solving and Python Programming Laboratory Program: alist = [-45,0,3,10,90,5,- 2,4,18,45,100,1,-266,706] largest = alist[0] for large in alist: if large > alist: largest = large print(“The Largest Number is:”,largest)
  • 8. GE 8161 – Problem Solving and Python Programming Laboratory Output: (‘The Largest of the List is:’, 706)
  • 9. GE 8161 – Problem Solving and Python Programming Laboratory Program: def Linearsearch(alist,item): pos=0 found=False stop=False while pos<len(alist) and not found and not stop: if alist[pos]==item: found=True print("Element found in position",pos) else: if alist[pos]>item: stop=True else: pos=pos+1 return found a=[] n=int(input("Enter upper limit")) for i in range(0,n): e=int(input("Enter the elements")) a.append(e) x=int(input("Enter element to search")) Linearsearch(a,x)
  • 10. GE 8161 – Problem Solving and Python Programming Laboratory Output: Enter upper limit:5 Enter the elements:1 Enter the elements:8 Enter the elements:9 Enter the elements:6 Enter the elements:7 Enter element to search:9 Element found in position: 2
  • 11. GE 8161 – Problem Solving and Python Programming Laboratory Program: def binarysearch(a,n,k): low = 0 high = n while(low<=high): mid=int((low+high)/2) if(k==a[mid]): return mid elif(k<a[mid]): high=mid-1 else: low=mid+1 return -1 n=int(input("Enter the size of list")) a=[i for i in range(n)] print(n) print("Enter the element") for i in range(0,n): a[i]=int(input()) print("Enter the element to be searched") k=int(input()) position=binarysearch(a,n,k) if(position!=-1): print("Entered no:%d is present:%d"%(k,position)) else: print("Entered no:%d is not present in list"%k)
  • 12. GE 8161 – Problem Solving and Python Programming Laboratory Output: Enter the size of list 5 Enter the element 1 8 6 3 4 Enter the element to be searched 1 Entered no:1 is present:0
  • 13. GE 8161 – Problem Solving and Python Programming Laboratory Program: def selectionSort(alist): for i in range(len(alist)-1,0,-1): pos=0 for location in range(1,i+1): if alist[location]>alist[pos]: pos= location temp = alist[i] alist[i] = alist[pos] alist[pos] = temp alist = [54,26,93,17,77,31,44,55,20] selectionSort(alist) print(alist)
  • 14. GE 8161 – Problem Solving and Python Programming Laboratory Output: [17, 20, 26, 31, 44, 54, 55, 77, 93]
  • 15. GE 8161 – Problem Solving and Python Programming Laboratory Program: def insertionSort(alist): for index in range(1,len(alist)): currentvalue = alist[index] position = index while position>0 and alist[position-1]>currentvalue: alist[position]=alist[position-1] position = position-1 alist[position]=currentvalue alist = [54,26,93,17,77,31,44,55,20] insertionSort(alist) print(alist)
  • 16. GE 8161 – Problem Solving and Python Programming Laboratory Output: [17, 20, 26, 31, 44, 54, 55, 77, 93]
  • 17. GE 8161 – Problem Solving and Python Programming Laboratory Program: def mergeSort(alist): print("Splitting ",alist) if len(alist)>1: mid = len(alist)//2 lefthalf = alist[:mid] righthalf = alist[mid:] mergeSort(lefthalf) mergeSort(righthalf) i=0 j=0 k=0 while i < len(lefthalf) and j < len(righthalf): if lefthalf[i] < righthalf[j]: alist[k]=lefthalf[i] i=i+1 else: alist[k]=righthalf[j] j=j+1 k=k+1 while i < len(lefthalf): alist[k]=lefthalf[i] i=i+1 k=k+1 while j < len(righthalf): alist[k]=righthalf[j] j=j+1 k=k+1 print("Merging ",alist) alist = [23, 6, 4 ,12, 9] mergeSort(alist) print(alist)
  • 18. GE 8161 – Problem Solving and Python Programming Laboratory Output: ('Splitting ', [23, 6, 4, 12, 9]) ('Splitting ', [23, 6]) ('Splitting ', [23]) ('Merging ', [23]) ('Splitting ', [6]) ('Merging ', [6]) ('Merging ', [6, 23]) ('Splitting ', [4, 12, 9]) ('Splitting ', [4]) ('Merging ', [4]) ('Splitting ', [12, 9]) ('Splitting ', [12]) ('Merging ', [12]) ('Splitting ', [9]) ('Merging ', [9]) ('Merging ', [9, 12]) ('Merging ', [4, 9, 12]) ('Merging ', [4, 6, 9, 12, 23]) [4, 6, 9, 12, 23]
  • 19. GE 8161 – Problem Solving and Python Programming Laboratory Program: i=1 x = int(input("Enter the Upper Limit:")) for k in range (1, (x+1), 1): c=0; for j in range (1, (i+1), 1): a = i%j if (a==0): c = c+1 if (c==2): print (i) else: k = k-1 i=i+1
  • 20. GE 8161 – Problem Solving and Python Programming Laboratory Output: Enter the Upper Limit:100 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
  • 21. GE 8161 – Problem Solving and Python Programming Laboratory Program: X= [[1,2,7], [4,5,6], [1,2,3]] Y= [[5,8,1], [6,7,3], [4,5,1]] result= [[0,0,0], [0,0,0], [0,0,0]] for i in range(len(X)): for j in range(len(Y[0])): for k in range(len(Y)): result[i][j]+=X[i][k]*Y[k][j] for r in result: print(r)
  • 22. GE 8161 – Problem Solving and Python Programming Laboratory Output: [45, 57, 14] [74, 97, 25] [29, 37, 10]
  • 23. GE 8161 – Problem Solving and Python Programming Laboratory Program: import sys if len(sys.argv)!=2: print('Error: filename missing') sys.exit(1) filename = sys.argv[1] file = open(filename, "r+") wordcount={} for word in file.read().split(): if word not in wordcount: wordcount[word] = 1 else: wordcount[word]+=1 for k,v in wordcount.items(): print (k, v)
  • 24. GE 8161 – Problem Solving and Python Programming Laboratory Output:
  • 25. GE 8161 – Problem Solving and Python Programming Laboratory Program: filename = input("Enter file name:") inf = open(filename,'r') wordcount={} for word in inf.read().split(): if word not in wordcount: wordcount[word] = 1 else: wordcount[word] += 1 for key in wordcount.keys(): print("%sn%sn"%(key, wordcount[key])) linecount = 0 for i in inf: paragraphcount = 0 if'n'in i: linecount += 1 if len(i)<2: paragraphcount *= 0 elif len(i)>2: paragraphcount = paragraphcount + 1 print('%-4dn%4dn%sn'%(paragraphcount,linecount,i)) inf.close()
  • 26. GE 8161 – Problem Solving and Python Programming Laboratory Output: Enter file name:'text.txt' a 1 used 1 for 1 language 1 Python 1 is 1 programming 2 general-purpose 1 widely 1 high-level 1
  • 27. GE 8161 – Problem Solving and Python Programming Laboratory Program: import pygame import math import sys pygame.init() screen = pygame.display.set_mode((600, 300)) pygame.display.set_caption("Elliptical orbit") clock = pygame.time.Clock() while(True): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() xRadius = 250 yRadius = 100 for degree in range(0,360,10): x1 = int(math.cos(degree * 2 * math.pi / 360) * xRadius) + 300 y1 = int(math.sin(degree * 2 * math.pi / 360) * yRadius) + 150 screen.fill((0, 0, 0)) pygame.draw.circle(screen, (255, 0, 0), [300, 150], 35) pygame.draw.ellipse(screen, (255, 255, 255), [50, 50, 500, 200], 1) pygame.draw.circle(screen, (0, 0, 255), [x1, y1], 15) pygame.display.flip() clock.tick(5)
  • 28. GE 8161 – Problem Solving and Python Programming Laboratory Output:
  • 29. GE 8161 – Problem Solving and Python Programming Laboratory Program: import pygame,sys,time,random from pygame.locals import* from time import* pygame.init() windowSurface=pygame.display.set_mode((500,400),0,32) pygame.display.set_caption("BOUNCE") BLACK=(0,0,0) WHITE=(255,255,255) RED=(255,0,0) GREEN=(0,255,0) BLUE=(0,0,255) info=pygame.display.Info() sw=info.current_w sh=info.current_h y=0 direction=1 while True: windowSurface.fill(BLACK) pygame.draw.circle(windowSurface,GREEN,(250,y),13,0) sleep(.006) y+=direction if y>=sh: direction=-1 elif y<=0: direction=1 pygame.display.update() for event in pygame.event.get(): if event.type==QUIT: pygame.quit() sys.exit()
  • 30. GE 8161 – Problem Solving and Python Programming Laboratory Output: