SlideShare a Scribd company logo
PDES SEM1 PYTHON PROGRAM EXERCISE
1#python program to add two num
a=int(input("Enter the number A:"))
b=int(input("Enter the number B:"))
c=a+b
print("Addition of Two Num is:",c)
2#SOLVE QUADRATIC EQ
import cmath
a=int(input("Enter the value A:"))
b=int(input("Enter the value B:"))
c=int(input("Enter the value C:"))
d= (b**2)-(4*a*c)
x1= (-b + cmath.sqrt(d))/(2*a)
x2= (-b - cmath.sqrt(d))/(2*a)
print("The Quadratic Eq :", x1, x2)
3#SWAP TWO VARIABLE
a=int(input("Enter the number A:"))
b=int(input("Enter the number B:"))
print("Before Swap: ", a, b)
a=a+b
b=a-b
a=a-b
print("After Swap: ", a, b)
4#CHECK NUM TO + - OR 0
a=int(input("Enter the number A:"))
if(a==0):
print("Enter num is Zero")
elif(a>0):
print("Enter num is Positive")
else:
print("Enter num is Negative")
5#FIND THE LARGEST AMONG 3 NUM
a=int(input("Enter the number A:"))
b=int(input("Enter the number B:"))
c=int(input("Enter the number C:"))
if(a>b and a>c):
print("A is Largest num ")
elif(b>c):
print("B is Largest num ")
else:
print("c is Largest num ")
6#CHECK PRIME NUM
a=int(input("Enter the number A:"))
flag= False
for i in range(2,a):
if(a%i==0):
flag= True
break
if(flag):
print("It is not a prime Num")
else:
print("It is a prime Num")
7#FACTORIAL OF A NUM
a=int(input("Enter the number A:"))
t=a
s=1
while(a>0):
s=s*a
a=a-1
print("Factorial of {0} is {1}". format(t,s))
8#FIBONACCI SEQUENCE
a=1
b=1
for i in range(10): #10 IS NUM OF SEQ FOR O/P
c=a+b
print(c)
a=b
b=c
9#ARMSTRONG NUM
a=int(input("Enter a Num:"))
s=0
temp=a
while(a>0):
r=a%10
s=s+r**3
a=a//10
if(temp==s):
print("The num is armstrong")
else:
print("The num is not armstrong")
10#SUM OF NATURAL NUM
a=int(input("Enter the number A:"))
b=int(input("Enter the number B:"))
sum=0
if(a>0 and b>0):
sum=a+b
print(sum)
else:
print("Entered num is not Natural")
11#DISPLAY POWER OF 2 USING ANONYMOUS FUNCTION
a=int(input("Term NUM:"))
b=int(input("Range:"))
result=list(map(lambda x:2**x,range(b)))
for i in range(b):
print(a,"**", i, "=", result[i])
12#FIND A NUM WHICH DIVISIBLE BY ANOTHER NUM
a=int(input("Enter a Num:"))
mlist=[1,2,3,4,5,6,7,8,9,10]
result=list(filter(lambda x:(x%a==0), mlist))
print(result)
13#CONVERT DECIMAL TO BINARY, OCTAL AND HEXA
a=int(input("Enter a decimal num:"))
print("Binary NUM:", bin(a))
print("Octal NUM:", oct(a))
print("Hexadecimal NUM:", hex(a))
34#remove a key from dictionary
my_dict={'hi':[2], 'how':[3], 'are you':[6], 'i am':[1,2], 'jayhari':[7]}
print("Dictionary is",my_dict)
#1st way
my_dict.pop('hi')
print(my_dict)
#2nd way
del my_dict['how']
print(my_dict)
14#SIMPLE CALCULATOR
print("1.ADDITION")
print("2.SUBSTRACTION")
print("3.MULTIPLICATION")
print("4.DIVISION")
a=int(input("Select Operation (1/2/3/4):"))
num1= int(input("Enter 1st Num:"))
num2= int(input("Enter 2st Num:"))
if a==1:
print("Addition of two num is :", num1+num2)
elif a==2:
print(" Substaction of two num is :", num1-num2)
elif a==3:
print("Multiplication of two num is :", num1*num2)
elif a==4:
print("Division of two num is :", num1/num2)
else:
print("Invalid Input")
15#DISPLAY FIBONACCI SEQUENCE USING RECURSION
def recur_fibo(n):
if n<=1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
term= int(input("Required Term:"))
print("Fibonacci seq ")
for i in range(term):
print(recur_fibo(i))
20#add two matrices
x=[[12,7,3],[4,5,6],[7,8,9]]
y=[[5,8,1],[6,7,8],[4,5,9]]
result= [[0,0,0],[0,0,0],[0,0,0]]
for i in range(len(x)):
for j in range(len(x[0])):
result[i][j] = x[i][j] + y[i][j]
for r in result:
print(r)
21#multiply two matrices
x=[[12,7,3],[4,5,6],[7,8,9]]
y=[[5,8,1],[6,7,3],[4,5,9]]
result= [[0,0,0],[0,0,0],[0,0,0]]
for i in range(len(x)):
for j in range(len(x[0])):
result[i][j] = x[i][j] * y[i][j]
for r in result:
print(r)
22# check wheather string is palindrome or not
string= input("Enter a string:")
if(string==string[::-1]):
print("Entered string is palindrome")
else:
print("Entered string is not palindrome")
23#remove a punctuation from string
p= '''!@#$%^&,./;'<>?:`~'''
s= ''' hello !? how, are $$ you !& '''
print("Before :",s)
no_p= ""
for char in s:
if char not in p:
no_p = no_p + char
print(no_p)
24#sort word in alphabetic order
s= str(input("Enter a String:"))
word= s.split()
word.sort()
print("The sorted words are :")
for word in word:
print(word)
25#illustrate different set operator
e={0,1,2,3}
n={2,5,9}
print("Union is", e|n)
print("intersection is", e&n)
print("summetric is", e^n)
26#count the num of each vowel
v='a e i o u'
ip_str=str(input("Enter a String:"))
ip_str=ip_str.casefold()
count={}.fromkeys(v,0)
for char in ip_str:
if char in count:
count[char]+=1
print(count[char])
print(count)
27#find sum of array
arr=[10,11,12,13,14,15,16,17,18]
sum=0
for i in range(len(arr)):
sum=sum+arr[i]
print(sum)
28#largest element in array
arr=[10,101,15,17,15,805]
n=len(arr)
max=arr[0]
for i in range(1,n):
if arr[i]>max:
max=arr[i]
print("Largest num in array:",max)
29#interchange first and last element of list
alist=[10,11,12,13,5]
print(alist)
size=len(alist)
temp=alist[0]
alist[0]=alist[size-1]
alist[size-1]=temp
print("After Interchange:",alist)
30#reversing a list
a=[10,1,2,6,8,23]
print("Before Reversing:",a)
a.reverse()
print("Reverse list: ",a)
31#size of tuple
a=("java","python","c","c++")
print("Defined Tuple ",a)
print("The size of Tuple is",len(a))
32#sort a list of tuple
a=[(1,8,3),(2,5,7),(1,0,1)]
print("Defined Tuple ",a)
a.sort()
print("Sorted tuple:",a)
33#extract unique value dictionary value
my_dict={'hi':[2], 'how':[3], 'are you':[6]}
print("Dictionary is",my_dict)
r=list(sorted({elem for val in my_dict.values() for elem in val}))
print("Unique value ",r)

More Related Content

PPTX
DDA algorithm
PPTX
Secant Method
PDF
Python Programming Strings
DOC
C lab-programs
PPT
Frequency Domain Filtering 1.ppt
PPT
Calculus 1
PPTX
Computer Graphic - Lines, Circles and Ellipse
PPTX
C programming language tutorial
DDA algorithm
Secant Method
Python Programming Strings
C lab-programs
Frequency Domain Filtering 1.ppt
Calculus 1
Computer Graphic - Lines, Circles and Ellipse
C programming language tutorial

What's hot (20)

PDF
Python Programming by Dr. C. Sreedhar.pdf
PPTX
GRPHICS01 - Introduction to 3D Graphics
PDF
Non-Local Means and its Applications
PPTX
Part 2- Geometric Transformation.pptx
PPT
Application of derivatives
PDF
Python Programming
PPTX
Topic: Fourier Series ( Periodic Function to change of interval)
PDF
Python Programming
PPT
3 intensity transformations and spatial filtering slides
PDF
Python Programming: Lists, Modules, Exceptions
PPTX
Circle generation algorithm
PDF
3.3 Rates of Change and Behavior of Graphs
PPTX
Oops presentation
PPTX
CATHODE RAY TUBE IN COMPUTER GRAPHICS
PPT
Windows and viewport
PPTX
Strings and pointers
PPT
05 histogram processing DIP
DOCX
Digtial Image Processing Q@A
PPTX
Error Finding in Numerical method
PPTX
Secant method
Python Programming by Dr. C. Sreedhar.pdf
GRPHICS01 - Introduction to 3D Graphics
Non-Local Means and its Applications
Part 2- Geometric Transformation.pptx
Application of derivatives
Python Programming
Topic: Fourier Series ( Periodic Function to change of interval)
Python Programming
3 intensity transformations and spatial filtering slides
Python Programming: Lists, Modules, Exceptions
Circle generation algorithm
3.3 Rates of Change and Behavior of Graphs
Oops presentation
CATHODE RAY TUBE IN COMPUTER GRAPHICS
Windows and viewport
Strings and pointers
05 histogram processing DIP
Digtial Image Processing Q@A
Error Finding in Numerical method
Secant method
Ad

Similar to PYTHON_PROGRAM(1-34).pdf (20)

PPTX
Basic Python Programs, Python Fundamentals.pptx
PDF
Python From Scratch (1).pdf
PPTX
Basic python programs
DOCX
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx
DOCX
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2.docx
PPTX
PRACTICAL FILE(COMP SC).pptx
PDF
calculator_new (1).pdf
DOCX
ECE-PYTHON.docx
PPTX
Presentation 6 (1).pptx
PDF
Practical File waale code.pdf
DOCX
Literary Genre MatrixPart 1 Matrix FictionNon-fiction.docx
PDF
Digital signal Processing all matlab code with Lab report
PPTX
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
PPTX
L25-L26-Parameter passing techniques.pptx
DOC
Basic c programs updated on 31.8.2020
PDF
C++ TUTORIAL 8
PDF
2D array
PPTX
Python Tidbits
DOCX
Matlab project
PDF
python practicals-solution-2019-20-class-xii.pdf
Basic Python Programs, Python Fundamentals.pptx
Python From Scratch (1).pdf
Basic python programs
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2.docx
PRACTICAL FILE(COMP SC).pptx
calculator_new (1).pdf
ECE-PYTHON.docx
Presentation 6 (1).pptx
Practical File waale code.pdf
Literary Genre MatrixPart 1 Matrix FictionNon-fiction.docx
Digital signal Processing all matlab code with Lab report
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
L25-L26-Parameter passing techniques.pptx
Basic c programs updated on 31.8.2020
C++ TUTORIAL 8
2D array
Python Tidbits
Matlab project
python practicals-solution-2019-20-class-xii.pdf
Ad

Recently uploaded (20)

PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
advance database management system book.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PPTX
Introduction to Building Materials
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
HVAC Specification 2024 according to central public works department
PDF
Trump Administration's workforce development strategy
PDF
Computing-Curriculum for Schools in Ghana
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
Empowerment Technology for Senior High School Guide
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
IGGE1 Understanding the Self1234567891011
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Chinmaya Tiranga quiz Grand Finale.pdf
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
advance database management system book.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Share_Module_2_Power_conflict_and_negotiation.pptx
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
Introduction to Building Materials
FORM 1 BIOLOGY MIND MAPS and their schemes
History, Philosophy and sociology of education (1).pptx
HVAC Specification 2024 according to central public works department
Trump Administration's workforce development strategy
Computing-Curriculum for Schools in Ghana
Indian roads congress 037 - 2012 Flexible pavement
Empowerment Technology for Senior High School Guide
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
IGGE1 Understanding the Self1234567891011
202450812 BayCHI UCSC-SV 20250812 v17.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS

PYTHON_PROGRAM(1-34).pdf

  • 1. PDES SEM1 PYTHON PROGRAM EXERCISE 1#python program to add two num a=int(input("Enter the number A:")) b=int(input("Enter the number B:")) c=a+b print("Addition of Two Num is:",c) 2#SOLVE QUADRATIC EQ import cmath a=int(input("Enter the value A:")) b=int(input("Enter the value B:")) c=int(input("Enter the value C:")) d= (b**2)-(4*a*c) x1= (-b + cmath.sqrt(d))/(2*a) x2= (-b - cmath.sqrt(d))/(2*a) print("The Quadratic Eq :", x1, x2) 3#SWAP TWO VARIABLE a=int(input("Enter the number A:")) b=int(input("Enter the number B:")) print("Before Swap: ", a, b) a=a+b b=a-b a=a-b print("After Swap: ", a, b)
  • 2. 4#CHECK NUM TO + - OR 0 a=int(input("Enter the number A:")) if(a==0): print("Enter num is Zero") elif(a>0): print("Enter num is Positive") else: print("Enter num is Negative") 5#FIND THE LARGEST AMONG 3 NUM a=int(input("Enter the number A:")) b=int(input("Enter the number B:")) c=int(input("Enter the number C:")) if(a>b and a>c): print("A is Largest num ") elif(b>c): print("B is Largest num ") else: print("c is Largest num ")
  • 3. 6#CHECK PRIME NUM a=int(input("Enter the number A:")) flag= False for i in range(2,a): if(a%i==0): flag= True break if(flag): print("It is not a prime Num") else: print("It is a prime Num") 7#FACTORIAL OF A NUM a=int(input("Enter the number A:")) t=a s=1 while(a>0): s=s*a a=a-1 print("Factorial of {0} is {1}". format(t,s))
  • 4. 8#FIBONACCI SEQUENCE a=1 b=1 for i in range(10): #10 IS NUM OF SEQ FOR O/P c=a+b print(c) a=b b=c 9#ARMSTRONG NUM a=int(input("Enter a Num:")) s=0 temp=a while(a>0): r=a%10 s=s+r**3 a=a//10 if(temp==s): print("The num is armstrong") else: print("The num is not armstrong")
  • 5. 10#SUM OF NATURAL NUM a=int(input("Enter the number A:")) b=int(input("Enter the number B:")) sum=0 if(a>0 and b>0): sum=a+b print(sum) else: print("Entered num is not Natural") 11#DISPLAY POWER OF 2 USING ANONYMOUS FUNCTION a=int(input("Term NUM:")) b=int(input("Range:")) result=list(map(lambda x:2**x,range(b))) for i in range(b): print(a,"**", i, "=", result[i])
  • 6. 12#FIND A NUM WHICH DIVISIBLE BY ANOTHER NUM a=int(input("Enter a Num:")) mlist=[1,2,3,4,5,6,7,8,9,10] result=list(filter(lambda x:(x%a==0), mlist)) print(result) 13#CONVERT DECIMAL TO BINARY, OCTAL AND HEXA a=int(input("Enter a decimal num:")) print("Binary NUM:", bin(a)) print("Octal NUM:", oct(a)) print("Hexadecimal NUM:", hex(a)) 34#remove a key from dictionary my_dict={'hi':[2], 'how':[3], 'are you':[6], 'i am':[1,2], 'jayhari':[7]} print("Dictionary is",my_dict) #1st way my_dict.pop('hi') print(my_dict) #2nd way del my_dict['how'] print(my_dict)
  • 7. 14#SIMPLE CALCULATOR print("1.ADDITION") print("2.SUBSTRACTION") print("3.MULTIPLICATION") print("4.DIVISION") a=int(input("Select Operation (1/2/3/4):")) num1= int(input("Enter 1st Num:")) num2= int(input("Enter 2st Num:")) if a==1: print("Addition of two num is :", num1+num2) elif a==2: print(" Substaction of two num is :", num1-num2) elif a==3: print("Multiplication of two num is :", num1*num2) elif a==4: print("Division of two num is :", num1/num2) else: print("Invalid Input")
  • 8. 15#DISPLAY FIBONACCI SEQUENCE USING RECURSION def recur_fibo(n): if n<=1: return n else: return(recur_fibo(n-1) + recur_fibo(n-2)) term= int(input("Required Term:")) print("Fibonacci seq ") for i in range(term): print(recur_fibo(i)) 20#add two matrices x=[[12,7,3],[4,5,6],[7,8,9]] y=[[5,8,1],[6,7,8],[4,5,9]] result= [[0,0,0],[0,0,0],[0,0,0]] for i in range(len(x)): for j in range(len(x[0])): result[i][j] = x[i][j] + y[i][j] for r in result: print(r)
  • 9. 21#multiply two matrices x=[[12,7,3],[4,5,6],[7,8,9]] y=[[5,8,1],[6,7,3],[4,5,9]] result= [[0,0,0],[0,0,0],[0,0,0]] for i in range(len(x)): for j in range(len(x[0])): result[i][j] = x[i][j] * y[i][j] for r in result: print(r) 22# check wheather string is palindrome or not string= input("Enter a string:") if(string==string[::-1]): print("Entered string is palindrome") else: print("Entered string is not palindrome") 23#remove a punctuation from string p= '''!@#$%^&,./;'<>?:`~''' s= ''' hello !? how, are $$ you !& ''' print("Before :",s) no_p= "" for char in s: if char not in p: no_p = no_p + char print(no_p)
  • 10. 24#sort word in alphabetic order s= str(input("Enter a String:")) word= s.split() word.sort() print("The sorted words are :") for word in word: print(word) 25#illustrate different set operator e={0,1,2,3} n={2,5,9} print("Union is", e|n) print("intersection is", e&n) print("summetric is", e^n) 26#count the num of each vowel v='a e i o u' ip_str=str(input("Enter a String:")) ip_str=ip_str.casefold() count={}.fromkeys(v,0) for char in ip_str: if char in count: count[char]+=1 print(count[char]) print(count)
  • 11. 27#find sum of array arr=[10,11,12,13,14,15,16,17,18] sum=0 for i in range(len(arr)): sum=sum+arr[i] print(sum) 28#largest element in array arr=[10,101,15,17,15,805] n=len(arr) max=arr[0] for i in range(1,n): if arr[i]>max: max=arr[i] print("Largest num in array:",max) 29#interchange first and last element of list alist=[10,11,12,13,5] print(alist) size=len(alist) temp=alist[0] alist[0]=alist[size-1] alist[size-1]=temp print("After Interchange:",alist)
  • 12. 30#reversing a list a=[10,1,2,6,8,23] print("Before Reversing:",a) a.reverse() print("Reverse list: ",a) 31#size of tuple a=("java","python","c","c++") print("Defined Tuple ",a) print("The size of Tuple is",len(a)) 32#sort a list of tuple a=[(1,8,3),(2,5,7),(1,0,1)] print("Defined Tuple ",a) a.sort() print("Sorted tuple:",a) 33#extract unique value dictionary value my_dict={'hi':[2], 'how':[3], 'are you':[6]} print("Dictionary is",my_dict) r=list(sorted({elem for val in my_dict.values() for elem in val})) print("Unique value ",r)