0% found this document useful (0 votes)
2 views

Python ESE practical list apna logic m

The document contains a list of 58 Python programs covering various topics such as basic arithmetic operations, data type conversions, control structures, and object-oriented programming. Each program is designed to perform a specific task, such as converting currencies, calculating areas, checking for prime numbers, and handling exceptions. The programs serve as examples for learning and practicing Python programming concepts.

Uploaded by

jadhavparam1906
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python ESE practical list apna logic m

The document contains a list of 58 Python programs covering various topics such as basic arithmetic operations, data type conversions, control structures, and object-oriented programming. Each program is designed to perform a specific task, such as converting currencies, calculating areas, checking for prime numbers, and handling exceptions. The programs serve as examples for learning and practicing Python programming concepts.

Uploaded by

jadhavparam1906
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

programs for the ESE Program List:

1. Display Name (Interactive Mode)


print("Your Name")

2. Display "MSBTE" (Script Mode)


print("MSBTE")

3. USD to INR Converter


usd = float(input("Enter USD: "))
inr = usd * 83
print(f"{usd} USD = {inr} INR")

4. Convert Bits to MB, GB, TB


bits = int(input("Enter bits: "))
bytes = bits / 8
kb = bytes / 1024
mb = kb / 1024
gb = mb / 1024
tb = gb / 1024
print(f"MB: {mb}, GB: {gb}, TB: {tb}")

5. Square Root
import math
num = float(input("Enter number: "))
print(math.sqrt(num))

6. Area of Rectangle
length = float(input("Length: "))
width = float(input("Width: "))
print(length * width)

7. Square Area & Perimeter


side = float(input("Side: "))
print(f"Area: {side**2}, Perimeter: {4*side}")

8. Cylinder Volume & Surface Area


import math
r = float(input("Radius: "))
h = float(input("Height: "))
print(f"Volume: {math.pi*r**2*h}")
print(f"Surface Area: {2*math.pi*r*(r+h)}")

9. Swap Variables
a, b = input("a: "), input("b: ")
a, b = b, a
print(f"a={a}, b={b}")

10. Even or Odd


num = int(input("Number: "))
print("Even" if num%2 ==0 else "Odd")
11. Absolute Value
print(abs(float(input("Number: "))))

12. Largest of Three


a, b, c = [float(input()) for _ in range(3)]
print(max(a, b, c))

13. Leap Year Check


year = int(input())
print("Leap" if (year%4==0 and year%100!=0) or year%400==0 else "Not Leap")

14. Positive/Negative/Zero
n = float(input())
print("Positive" if n>0 else "Negative" if n<0 else "Zero")

15. Grade Calculator


marks = [int(input(f"Sub {i+1}: ")) for i in range(5)]
avg = sum(marks)/5
print("A" if avg>=90 else "B" if avg>=80 else "C" if avg>=70 else "D" if avg>=60 else "Fail")

16. Even Numbers 1-100 (While Loop)


n=1
while n <= 100:
if n%2 == 0: print(n)
n += 1

17. Sum of First 10 Naturals


print(sum(range(1,11)))

18. Fibonacci Series


n = int(input("Terms: "))
a, b = 0, 1
for _ in range(n):
print(a, end=' ')
a, b = b, a+b

19. Factorial
n = int(input())
fact = 1
for i in range(1,n+1): fact *= i
print(fact)

20. Reverse Number


num = int(input())
rev = 0
while num>0:
rev = rev*10 + num%10
num //=10
print(rev)
21. Sum of Digits
print(sum(int(d) for d in input()))

22. Palindrome Check


num = input()
print("Palindrome" if num == num[::-1] else "Not Palindrome")

23. Sum List Items


nums = list(map(int, input().split()))
print(sum(nums))

24. Multiply List Items


nums = list(map(int, input().split()))
p=1
for n in nums: p *= n
print(p)

25. Largest in List


print(max(list(map(int, input().split()))))

26. Smallest in List


print(min(list(map(int, input().split()))))

27. Reverse List


lst = input().split()
print(lst[::-1])

28. Common List Items


a = input().split()
b = input().split()
print(list(set(a) & set(b)))

29. Even Items in List


print([x for x in list(map(int, input().split())) if x%2 ==0])

30. Min/Max in Tuple


t = tuple(map(int, input().split()))
print(f"Min: {min(t)}, Max: {max(t)}")

31. Repeated Tuple Items


from collections import Counter
t = tuple(input().split())
print([k for k,v in Counter(t).items() if v>1])

32. Number to Words


words = {'0':'Zero','1':'One','2':'Two','3':'Three','4':'Four','5':'Five','6':'Six','7':'Seven','8':'Eight','9':'Nine'}
num = input()
print(' '.join([words[d] for d in num]))
33. Set Operations
s = {1,2}
s.add(3)
s.remove(1)
print(s)

34. Set Functions


a = {1,2,3}; b = {3,4,5}
print(f"Union: {a|b}\nIntersection: {a&b}\nDifference: {a-b}\nSymmetric Diff: {a^b}")
a.clear()

35. Max/Min in Set


s = {5,3,9,1}
print(f"Max: {max(s)}, Min: {min(s)}")

36. Set Length


print(len({1,2,3}))

37. Sort Dictionary by Value


d = {'a':3, 'b':1, 'c':2}
print(dict(sorted(d.items(), key=lambda x:x[1])))

38. Merge Dictionaries


dic1 = {1:10}; dic2 = {2:20}; dic3 = {3:30}
print({**dic1, **dic2, **dic3})

38. Combine Dictionary Values


d1 = {'a':100, 'b':200}; d2 = {'a':300, 'b':200}
merged = {}
for k in d1.keys()|d2.keys():
merged[k] = d1.get(k,0) + d2.get(k,0)
print(merged)

39. Unique Dictionary Values


data = [{"V":"S001"}, {"V":"S002"}, {"VI":"S001"}]
print(set(v for d in data for v in d.values()))

40. Highest 3 Dictionary Values


d = {'a':500, 'b':200, 'c':300}
print(sorted(d.values(), reverse=True)[:3])

41. Count Uppercase/Lowercase


s = input()
print(f"Upper: {sum(c.isupper() for c in s)}, Lower: {sum(c.islower() for c in s)}")

42. Random Float 5-50


import random
print(random.uniform(5,50))
43. Prime Check Function
def is_prime(n):
if n <=1: return False
for i in range(2, int(n**0.5)+1):
if n%i ==0: return False
return True

print(is_prime(int(input())))

44. Factorial Function


def factorial(n):
return 1 if n==0 else n*factorial(n-1)

print(factorial(int(input())))

45. Same as 41
# Refer to program 41

46. College Name Module

Create college.py:
def display_college():
print("College Name: " + input("Enter college name: "))

Usage:
import college
college.display_college()

47. Circle Area & Circumference


import math
r = float(input())
print(f"Area: {math.pi*r**2}, Circumference: {2*math.pi*r}")

48. Display Calendar


import calendar
y, m = int(input()), int(input())
print(calendar.month(y,m))

49. Matrix Operations


m1 = [[1,2],[3,4]]; m2 = [[5,6],[7,8]]
print("Add:", [[i+j for i,j in zip(row1,row2)] for row1,row2 in zip(m1,m2)])

50. Concatenate Strings


print(input() + input())

51. Random Integers with NumPy


import numpy as np
print(np.random.randint(10,30,6))
52. Area Class
class Area:
def calculate(self, a, b=None):
return a*a if not b else a*b

a = Area()
print(a.calculate(5)) # Square
print(a.calculate(5,4)) # Rectangle

53. Degree Classes


class Degree:
def getDegree(self): print("I got a degree")

class Undergraduate(Degree):
def getDegree(self): print("I am an Undergraduate")

class Postgraduate(Degree):
def getDegree(self): print("I am a Postgraduate")

Degree().getDegree()
Undergraduate().getDegree()
Postgraduate().getDegree()

54. Employee Class


class Employee:
def __init__(self, name, dept, salary):
self.name = name
self.dept = dept
self.salary = salary

def display(self):
print(f"Name: {self.name}, Dept: {self.dept}, Salary: {self.salary}")

emp = Employee("John", "IT", 50000)


emp.display()

55. Student Inheritance


class Student:
def __init__(self, name, roll):
self.name = name
self.roll = roll

class StudentInfo(Student):
def display(self):
print(f"Name: {self.name}, Roll: {self.roll}")

info = StudentInfo("Alice", 101)


info.display()
56. Multiple Inheritance
class Father:
def method1(self): print("Father method")

class Mother:
def method2(self): print("Mother method")

class Child(Father, Mother): pass

c = Child()
c.method1()
c.method2()

57. ZeroDivisionError Check


try:
print(5/0)
except ZeroDivisionError:
print("Cannot divide by zero")

58. Password Exception


class PasswordError(Exception): pass

try:
if input("Password: ") != "secret":
raise PasswordError
except PasswordError:
print("Incorrect password")
else:
print("Access granted")

You might also like