diff --git a/asgn1.py b/asgn1.py new file mode 100644 index 0000000..5fae12e --- /dev/null +++ b/asgn1.py @@ -0,0 +1,46 @@ + +# # sorry I don't get the number eight question 8. Create a `School` object and threee students, add first 2 students to school. Print students and afterwards try to add the third student. + +# 9. Use `__dict__` method to see attributes +# s=[] +# while len(s)<=4: +# x=str(input('inter')) +# s.append(x) +# print(s) + +# class school(): +# students=[] +# def __init__(self,capacity): +# self.capacity=capacity +# def add_student(self): +# while True: +# if len(capacity_obj.students)<=self.capacity: +# student_name=input('enter student name') +# capacity_obj.students.append(student_name) +# print(capacity_obj.students) + +# else: +# if len(capacity_obj.students)>self.capacity: +# print('error;beyoned the capacity') +# break +# def print_student(self): +# ad_st=capacity_obj.add_student() +# for student in capacity_obj.students: +# print(student,end=', ') +# capacity_obj=school(3) +# capacity_obj.add_student() +# print(capacity_obj.print_student()) + +class student(): + def __init__(self,name,age,gender) : + self.name=name + self.age=age + self.gender=gender + def __str__(self) : + return f'{self.name},{self.age},{self.gender}' + + + +student_obj=student('name','age','gender') +print(student_obj) +print(student_obj.__dict__) \ No newline at end of file diff --git a/asgn2.py b/asgn2.py new file mode 100644 index 0000000..459716a --- /dev/null +++ b/asgn2.py @@ -0,0 +1,30 @@ +# 1. Write a `Rectangle` class, allowing you to build a rectangle with `length` +# and `width` attributes. + +# 2. Create a `perimeter()` method to calculate the perimeter +# of the rectangle and an `area()` method to calculate the area of ​​the rectangle. + +# 3. Create a method `display()` that displays the length, width, perimeter and area of an +# object created using an instantiation on `Rectangle` class. + +from operator import length_hint + + +class rectangle(): + + def __init__(self,width,lenght): + self.width=width + self.lenght=lenght + + def perimeter(self): + perimeter=(self.lenght +self.width)*2 + return perimeter + def area(self): + area=self.lenght*self.width + return area + def display(self): + x=rectangle.area() + y=rectangle.perimeter() + return f'lenght:{self.lenght}, width:{self.width},area:{x},perimeter:{y}' +rectangle=rectangle(3,4) +print(rectangle.display()) diff --git a/asgn3.py b/asgn3.py new file mode 100644 index 0000000..c2a3edd --- /dev/null +++ b/asgn3.py @@ -0,0 +1,47 @@ +# 1. Create a Python class called `BankAccount` which represents a bank account, having as attributes: +# `accountNumber`, `name` , `balance`. + +# 2. Create a **constructor** with parameters: `accountNumber`, `name`, `balance`. +# 3. Create a `deposit()` method which manages the deposit actions. (deposit() method will take parameter +# d and you will increase the balance with the amount d) + +# 4. Create a `withdrawal()` method which manages withdrawals actions. (withdrawal() +# method will take parameter w, you will reduce the amount of balance with w, if w is larger than the balance: +# then print `Impossible operation! Insufficient balance!"`) + + +# 5. Create a `bankFees()` method to apply the bank fees with a percentage of 5% of the balance account. +# (When this method is called, the balance amount should reduce 5%) +# 6. Create a `display()` method to display account details. +class BankAccount(): + def __init__(self,accountNumber,name,balance): + self.accountNumber=accountNumber + self.name=name + self.balance=balance + def deposit(self): + d=float(input('enter the amount you want to deposit: ')) + self.balance+=d + return self.balance + def withdrawal(self): + w=float(input('enter the withdrawal amount')) + if self.balance >= w: + return self.balance-w + else: + print('mpossible operation! Insufficient balance!') + def bankFees(self): + return self.balance*.05 + def display(self): + y=input('which operation would you like to undertake,withdraw or disposit? for disposit ener d for withdraw w: ').lower() + if y=='d': + dip=bankdetail.deposit() + return f'account number: {self.accountNumber} -accountholder: {self.name} -current balance: {dip}' + elif y=='w': + wit=bankdetail.withdrawal() + fe=bankdetail.bankFees() + return f'account number:{self.accountNumber} -Accountholder:{self.name} -current balance:{wit} nankfee:{fe}' + + + +bankdetail=BankAccount('w12e3r4','tamerat',50) +print(bankdetail.display()) + \ No newline at end of file