From cb94020a0b767800a783767e77ce3a35c0a86f88 Mon Sep 17 00:00:00 2001 From: gridliner Date: Mon, 17 Oct 2022 15:57:19 +0200 Subject: [PATCH 1/4] first commit w4 --- asgn1.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ asgn2.py | 30 ++++++++++++++++++++++++++++ asgn3.py | 0 3 files changed, 89 insertions(+) create mode 100644 asgn1.py create mode 100644 asgn2.py create mode 100644 asgn3.py diff --git a/asgn1.py b/asgn1.py new file mode 100644 index 0000000..9fce84d --- /dev/null +++ b/asgn1.py @@ -0,0 +1,59 @@ +# 1. Create a `School` class with instance attribute `capacity`. +# 2. Add `students` as the class attribute. This will be a list and keep track of the students in the school. +# 3. Create a `Student` class with attributes: `name`, `age`, `gender` +# 4. Add `__str__` method to this class to print the objects. +# 6. Add `add_student` method to the class. If capacity is full print error message else add the student. + +# 7. Add `print_students` method to print the all existing students. Loop through the students list and +# print each student object. + +# 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 len(capacity.students)<= self.capacity: +# student_name=(input('enter student name')) +# capacity.students.append(student_name) +# return capacity.students +# else: +# print('error') + + +# capacity=school(3) +# print(capacity.add_student()) + +def s(): + l=[] + while len(l)<=2: + d=input('enter n') + l.append(d) + print(l,end='') + else: + print('error') +s() + + + + +# class student(): +# def __init__(self,name,age,gender) : +# self.name=name +# self.age=age +# self.gender=gender +# def __str__(self) : +# "name is % s, " "age is % s" "gender is % s" % (self.a, self.b) + +# def add_student(self): + diff --git a/asgn2.py b/asgn2.py new file mode 100644 index 0000000..8d60556 --- /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() + print(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..e69de29 From ecb8e564f5133ae144f2e2268046e24874b7e464 Mon Sep 17 00:00:00 2001 From: gridliner Date: Mon, 17 Oct 2022 19:10:41 +0200 Subject: [PATCH 2/4] third commit --- asgn3.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/asgn3.py b/asgn3.py index e69de29..c2a3edd 100644 --- a/asgn3.py +++ 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 From c49662766a9eaae99d4d38bba97b5814fbce5e89 Mon Sep 17 00:00:00 2001 From: gridliner Date: Tue, 18 Oct 2022 00:03:09 +0200 Subject: [PATCH 3/4] forth commit --- asgn1.py | 57 ++++++++++++++++++++++++++------------------------------ asgn2.py | 2 +- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/asgn1.py b/asgn1.py index 9fce84d..e85c8ea 100644 --- a/asgn1.py +++ b/asgn1.py @@ -22,38 +22,33 @@ # 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) -# while len(capacity.students)<= self.capacity: -# student_name=(input('enter student name')) -# capacity.students.append(student_name) -# return capacity.students -# else: -# print('error') +# 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()) - -# capacity=school(3) -# print(capacity.add_student()) - -def s(): - l=[] - while len(l)<=2: - d=input('enter n') - l.append(d) - print(l,end='') - else: - print('error') -s() - - - +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}' + #"name is % s, " "age is % s" "gender is % s" % (self.name, self.age,self.gender) -# class student(): -# def __init__(self,name,age,gender) : -# self.name=name -# self.age=age -# self.gender=gender -# def __str__(self) : -# "name is % s, " "age is % s" "gender is % s" % (self.a, self.b) - -# def add_student(self): +student_obj=student('name','age','gender') +print(student_obj) \ No newline at end of file diff --git a/asgn2.py b/asgn2.py index 8d60556..459716a 100644 --- a/asgn2.py +++ b/asgn2.py @@ -25,6 +25,6 @@ def area(self): def display(self): x=rectangle.area() y=rectangle.perimeter() - print(f'lenght:{self.lenght}, width:{self.width},area:{x},perimeter:{y}') + return f'lenght:{self.lenght}, width:{self.width},area:{x},perimeter:{y}' rectangle=rectangle(3,4) print(rectangle.display()) From 649f216cf545ac3a307c5e872a79b5883edee9e9 Mon Sep 17 00:00:00 2001 From: gridliner Date: Tue, 18 Oct 2022 19:50:31 +0200 Subject: [PATCH 4/4] last commit --- asgn1.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/asgn1.py b/asgn1.py index e85c8ea..5fae12e 100644 --- a/asgn1.py +++ b/asgn1.py @@ -1,14 +1,5 @@ -# 1. Create a `School` class with instance attribute `capacity`. -# 2. Add `students` as the class attribute. This will be a list and keep track of the students in the school. -# 3. Create a `Student` class with attributes: `name`, `age`, `gender` -# 4. Add `__str__` method to this class to print the objects. -# 6. Add `add_student` method to the class. If capacity is full print error message else add the student. -# 7. Add `print_students` method to print the all existing students. Loop through the students list and -# print each student object. - -# 8. Create a `School` object and threee students, add first 2 students to school. -# Print students and afterwards try to add the third student. +# # 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=[] @@ -47,8 +38,9 @@ def __init__(self,name,age,gender) : self.gender=gender def __str__(self) : return f'{self.name},{self.age},{self.gender}' - #"name is % s, " "age is % s" "gender is % s" % (self.name, self.age,self.gender) + student_obj=student('name','age','gender') -print(student_obj) \ No newline at end of file +print(student_obj) +print(student_obj.__dict__) \ No newline at end of file