





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






class Student: def init(self, roll_no, name, marks1, marks2, marks3): self.roll_no = roll_no self.name = name self.marks = [marks1, marks2, marks3] def calculate_percentage(self): total_marks = sum(self.marks) percentage = (total_marks / 300) * 100 return percentage def display(self): percentage = self.calculate_percentage() print(f"Roll No: {self.roll_no}") print(f"Name: {self.name}") print(f"Marks: {self.marks[0]}, {self.marks[1]}, {self.marks[2]}") print(f"Percentage: {percentage:.2f}%") class StudentDatabase: def init(self): self.students = {} def add_student(self, roll_no, name, marks1, marks2, marks3): if roll_no in self.students: print("Student with this Roll No already exists.") else: self.students[roll_no] = Student(roll_no, name, marks1, marks2, marks3) print("Student added successfully.")
def delete_student(self, roll_no): if roll_no in self.students: del self.students[roll_no] print("Student deleted successfully.") else: print("Student with this Roll No does not exist.") def display_all_students(self): if not self.students: print("No students to display.") for student in self.students.values(): student.display() print("-" * 30)
def main(): db = StudentDatabase() while True: print("\nStudent Database Menu") print("1. Add Student") print("2. Delete Student") print("3. Display All Students") print("4. Exit") choice = input("Enter your choice: ") if choice == '1': roll_no = input("Enter Roll No: ") name = input("Enter Name: ") marks1 = float(input("Enter Marks in Subject 1: "))
class Circle: def init(self, center, radius): self.center = center self.radius = radius def str(self): return f"Circle with center at {self.center} and radius {self.radius}" def main():
x = float(input("Enter the x-coordinate of the center: ")) y = float(input("Enter the y-coordinate of the center: ")) radius = float(input("Enter the radius of the circle: "))
center = Point(x, y)
circle = Circle(center, radius)
print(circle) if name == "main": main()
class MyClass:
def Get(self): self.MyStr=input("Enter any String:") def Display(self): s=self.MyStr print("Upper Case:", s.upper()) cnt=len(s) i=cnt- RevStr="" while(i>=0): RevStr=RevStr+s[i] i=i- print("Reverse & Lower case:",RevStr.lower()) a=MyClass() a.Get() a.Display()
class Complex(): def initComplex(self): self.realPart = int(input("Enter the Real Part: ")) self.imgPart = int(input("Enter the Imaginary Part: ")) def display(self): print(self.realPart,"+",self.imgPart,"i", sep="") def sum(self, c1, c2): self.realPart = c1.realPart + c2.realPart
def Perimeter(self): return 2*(self.length+self.width) l=int(input("Enter length of Rectangle:")) w=int(input("Enter width of Rectangle:")) obj= Rectangle(l,w) print("Area of Rectangle:", round(obj.area(),2)) print("Area of Rectangle:", round(obj.Perimeter(),2))
class Point: def init(self, center=(0,0)): self.x = center[0] self.y = center[1] def print_point(self): print("The point is at ({x}, {y})".format(x=self.x, y=self.y)) class Circle: def init(self, center, radius): self.center = Point(center) self.radius = radius def print_circle(self): print("The circle's center is at ({x}, {y}) and a radius of {radius}" .format(x=self.center.x, y=self.center.y, radius=self.radius)) def point_in_circle(c, p): if ((p.x <= c.center.x+c.radius and p.x >= c.center.x-c.radius) and (p.y <= c.center.y+c.radius and p.y >= c.center.y-c.radius)): return True else: return False
class StringRepeater: def init(self,input_string): self.input_string = input_string def mul(self, n): if isinstance(n, int): return self.input_string*n else: raise ValueError("The repetition factor should be an integer") #Get input from the user user_input_string = input("Enter a string:") repetition_factor =int(input("Enter the repetition factor (an integer):"))