0% found this document useful (0 votes)
0 views3 pages

Full Python Practicals

This document contains 24 practical Python programs covering various concepts such as finding the largest of two numbers, checking even or odd, calculating factorial, identifying prime numbers, and handling exceptions. It also includes examples of list operations, tuple manipulations, dictionary operations, and object-oriented programming. Each program is presented with concise code snippets and brief descriptions of their functionality.

Uploaded by

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

Full Python Practicals

This document contains 24 practical Python programs covering various concepts such as finding the largest of two numbers, checking even or odd, calculating factorial, identifying prime numbers, and handling exceptions. It also includes examples of list operations, tuple manipulations, dictionary operations, and object-oriented programming. Each program is presented with concise code snippets and brief descriptions of their functionality.

Uploaded by

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

Complete Python Practical Programs (24

Programs)

1. Largest of Two Numbers


a=int(input()); b=int(input()); print(max(a,b))

2. Even or Odd
n=int(input()); print('Even' if n%2==0 else 'Odd')

3. First 10 Numbers
for i in range(1,11): print(i)

4. Factorial (Loop)
n=int(input()); f=1
for i in range(1,n+1): f*=i
print(f)

5. Prime Number
n=int(input()); print(all(n%i for i in range(2,n)))

6. Palindrome
s=input(); print(s==s[::-1])

7. String Functions
s='python'; print(len(s), [Link]('o'))

8. Print List
l=[1,2,3]; print(l)

9. Reverse List
l=[1,2,3]; [Link](); print(l)

10. Search List


l=[1,2,3]; x=2; print(x in l)

11. Clear List


l=[1,2]; [Link](); print(l)

12. Copy List


l=[1,2]; l2=[Link](); print(l2)

13. Max Min


l=[1,5,2]; print(max(l),min(l))

14. Tuple Length


t=(1,2,3); print(len(t))

15. Remove Tuple


l=[(1,2),(3,4)]; [Link]((1,2)); print(l)

16. Sort Tuples


l=[(2,1),(1,2)]; [Link](); print(l)

17. Dictionary Ops


d={'a':1}; d['b']=2; print(d)

18. Swap
a=1;b=2;a,b=b,a;print(a,b)

19. Fibonacci
def f(n): return n if n<=1 else f(n-1)+f(n-2)
print([f(i) for i in range(5)])

20. Class Object


class A:
def __init__(s): print('Hi')
A()
21. Exception
try:
a=1/0
except: print('Error')

22. File Handling


open('[Link]','w').write('Hi')

23. Multiple Exception Handling


try:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print(num1/num2)

except ZeroDivisionError:
print("Cannot divide by zero")
except ValueError:
print("Invalid input")
except Exception as e:
print(e)
finally:
print("Done")

24. OOP + String + List Combined


class Base:
def __init__(self):
print("Base constructor")
def __del__(self):
print("Base destructor")

class Derived(Base):
def __init__(self):
super().__init__()
print("Derived constructor")
def __del__(self):
print("Derived destructor")
super().__del__()

def analyze(self, text):


v="aeiouAEIOU"
vc=cc=0
for ch in text:
if [Link]():
if ch in v: vc+=1
else: cc+=1
print("Vowels:",vc,"Consonants:",cc,"Words:",len([Link]()))

def list_ops(self):
l=list(map(int,input().split()))
l=list(set(l))
[Link]()
print("2nd largest:", l[-2] if len(l)>1 else "NA")

obj=Derived()
[Link](input("Enter string: "))
obj.list_ops()
del obj

You might also like