SlideShare a Scribd company logo
1 of 30
Download to read offline
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

Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchHema Kashyap
Β 
How to use Map() Filter() and Reduce() functions in Python | Edureka
How to use Map() Filter() and Reduce() functions in Python | EdurekaHow to use Map() Filter() and Reduce() functions in Python | Edureka
How to use Map() Filter() and Reduce() functions in Python | EdurekaEdureka!
Β 
Python idle introduction(3)
Python idle introduction(3)Python idle introduction(3)
Python idle introduction(3)Fahad Ashrafi
Β 
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCE
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCEIntelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCE
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCEKhushboo Pal
Β 
Constructors in C++
Constructors in C++Constructors in C++
Constructors in C++RubaNagarajan
Β 
The fundamentals of Machine Learning
The fundamentals of Machine LearningThe fundamentals of Machine Learning
The fundamentals of Machine LearningHichem Felouat
Β 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
Β 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++Arpita Patel
Β 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHMI. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHMvikas dhakane
Β 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in clavanya marichamy
Β 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial IntelligenceMhd Sb
Β 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automataProf. Dr. K. Adisesha
Β 
L03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicL03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicManjula V
Β 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
Β 
Python Programming
Python ProgrammingPython Programming
Python ProgrammingSaravanan T.M
Β 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
Β 

What's hot (20)

Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
Β 
How to use Map() Filter() and Reduce() functions in Python | Edureka
How to use Map() Filter() and Reduce() functions in Python | EdurekaHow to use Map() Filter() and Reduce() functions in Python | Edureka
How to use Map() Filter() and Reduce() functions in Python | Edureka
Β 
Python idle introduction(3)
Python idle introduction(3)Python idle introduction(3)
Python idle introduction(3)
Β 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
Β 
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCE
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCEIntelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCE
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCE
Β 
Constructors in C++
Constructors in C++Constructors in C++
Constructors in C++
Β 
The fundamentals of Machine Learning
The fundamentals of Machine LearningThe fundamentals of Machine Learning
The fundamentals of Machine Learning
Β 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
Β 
Printf and scanf
Printf and scanfPrintf and scanf
Printf and scanf
Β 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Β 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
Β 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHMI. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
Β 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
Β 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
Β 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
Β 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
Β 
L03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicL03 ai - knowledge representation using logic
L03 ai - knowledge representation using logic
Β 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Β 
Python Programming
Python ProgrammingPython Programming
Python Programming
Β 
Functions in c language
Functions in c language Functions in c language
Functions in c language
Β 

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 3Abdul Haseeb
Β 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
Β 
Pythonic Math
Pythonic MathPythonic Math
Pythonic MathKirby Urner
Β 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysisDr. Rajdeep Chatterjee
Β 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_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 TestingTao Xie
Β 
Perm winter school 2014.01.31
Perm winter school 2014.01.31Perm winter school 2014.01.31
Perm winter school 2014.01.31Vyacheslav 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 algortihmSajid Marwat
Β 
R Language Introduction
R Language IntroductionR Language Introduction
R Language IntroductionKhaled Al-Shamaa
Β 
Advanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdfAdvanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdfSheba41
Β 
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.pptAnishaJ7
Β 
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 revisionafsheenfaiq2
Β 

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

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
Β 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
Β 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
Β 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
Β 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
Β 
Model Call Girl in Narela Delhi reach out to us at πŸ”8264348440πŸ”
Model Call Girl in Narela Delhi reach out to us at πŸ”8264348440πŸ”Model Call Girl in Narela Delhi reach out to us at πŸ”8264348440πŸ”
Model Call Girl in Narela Delhi reach out to us at πŸ”8264348440πŸ”soniya singh
Β 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
Β 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
Β 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
Β 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
Β 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
Β 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
Β 
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
Β 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
Β 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
Β 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
Β 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
Β 

Recently uploaded (20)

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
Β 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Β 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
Β 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Β 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
Β 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
Β 
Model Call Girl in Narela Delhi reach out to us at πŸ”8264348440πŸ”
Model Call Girl in Narela Delhi reach out to us at πŸ”8264348440πŸ”Model Call Girl in Narela Delhi reach out to us at πŸ”8264348440πŸ”
Model Call Girl in Narela Delhi reach out to us at πŸ”8264348440πŸ”
Β 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
Β 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
Β 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Β 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
Β 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
Β 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Β 
β˜… CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
β˜… CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCRβ˜… CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
β˜… CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
Β 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
Β 
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
Β 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
Β 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Β 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
Β 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
Β 

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: