Ad:
Q1. Write a Python program to Input 2 students percentage and find greater using parameterized constructor. 1
class Greater: def __init__(self, a, b): self.p1=a self.p2=b def calculate(self): if self.p1>self.p2: print("Greater percentage =",self.p1) else: print("Greater percentage =",self.p2) a=float(input("Enter 1st Number: ")) b=float(input("Enter 2nd Number: ")) g=Greater(a, b) g.calculate()
Q2. Write a Python program to Input 2 students percentage and find greater using parameterized constructor, Note: compare 2 object rather than comparing values. 1
class Greater: def __init__(self, a): self.percentage=a def compare(self, g2): if self.percentage>g2.percentage: return True else: return False g1=Greater(float(input("Enter 1st Percentage: "))) g2=Greater(float(input("Enter 2nd Percentage: "))) if g1.compare(g2): print("Greater percentage =",g1.percentage) else: print("Greater percentage =",g2.percentage)
Ad: