Python ESE practical list apna logic m
Python ESE practical list apna logic m
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)
9. Swap Variables
a, b = input("a: "), input("b: ")
a, b = b, a
print(f"a={a}, b={b}")
14. Positive/Negative/Zero
n = float(input())
print("Positive" if n>0 else "Negative" if n<0 else "Zero")
19. Factorial
n = int(input())
fact = 1
for i in range(1,n+1): fact *= i
print(fact)
print(is_prime(int(input())))
print(factorial(int(input())))
45. Same as 41
# Refer to program 41
Create college.py:
def display_college():
print("College Name: " + input("Enter college name: "))
Usage:
import college
college.display_college()
a = Area()
print(a.calculate(5)) # Square
print(a.calculate(5,4)) # Rectangle
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()
def display(self):
print(f"Name: {self.name}, Dept: {self.dept}, Salary: {self.salary}")
class StudentInfo(Student):
def display(self):
print(f"Name: {self.name}, Roll: {self.roll}")
class Mother:
def method2(self): print("Mother method")
c = Child()
c.method1()
c.method2()
try:
if input("Password: ") != "secret":
raise PasswordError
except PasswordError:
print("Incorrect password")
else:
print("Access granted")