diff --git a/Introduction-to-Data-Science/Session-6/aakash_singh/q10.py b/Introduction-to-Data-Science/Session-6/aakash_singh/q10.py new file mode 100644 index 0000000..8f160e1 --- /dev/null +++ b/Introduction-to-Data-Science/Session-6/aakash_singh/q10.py @@ -0,0 +1,35 @@ +class person: + def __init__(self, first_name='', last_name='', phone_number='', email=[]): + self.first_name = first_name + self.last_name = last_name + self.phone_number = phone_number + self.email = email + + def __str__(self): + s = self.first_name+' '+self.last_name+'\n'+self.phone_number+'\n' + for e in self.email: + s += e+'\n' + return s.strip() + + def __repr__(self): + return self.__str__() + + +class address_book: + def __init__(self): + self.ad_book = [] + + def add_contact(self): + newPerson = person() + newPerson.first_name = input('first name: ') + newPerson.last_name = input('last name: ') + newPerson.phone_number = input('phone number: ') + for i in range(int(input('enter number of email: '))): + newPerson.email.append(input('email {}: '.format(i+1))) + self.ad_book.append(newPerson) + + def lookup_contact(self, ln): + for i in self.ad_book: + if ln == i.last_name: + print(i) + return \ No newline at end of file diff --git a/Introduction-to-Data-Science/Session-6/aakash_singh/q9.py b/Introduction-to-Data-Science/Session-6/aakash_singh/q9.py new file mode 100644 index 0000000..6ca0335 --- /dev/null +++ b/Introduction-to-Data-Science/Session-6/aakash_singh/q9.py @@ -0,0 +1,43 @@ +import random + + +class deck: + class card: + def __init__(self, suit, val): + self.suit = suit + self.val = val + + def __str__(self): + return '{} {}'.format(self.suit, self.val) + + def __repr__(self): + return self.__str__() + + __suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'] + __values = ['A', '2', '3', '4', '5', '6', + '7', '8', '9', '10', 'J', 'Q', 'K'] + + Deck = [] + + def deal(self,suit,value): + i=0 + for i in range(len(self.Deck)): + if self.Deck[i].suit==suit and self.Deck[i].val==value: + del self.Deck[i] + print('del') + return + + def __init__(self): + random.seed() + for i in self.__suits: + for j in self.__values: + self.Deck.append(self.card(i, j)) + + def swap(self, a, b): + self.Deck[a], self.Deck[b] = self.Deck[b], self.Deck[a] + + def shuffle(self): + if len(self.Deck) != 52: + self.__init__() + for i in range(1000): + self.swap(random.randrange(0, 52), random.randrange(0, 52)) \ No newline at end of file diff --git a/Introduction-to-Data-Science/Session-6/aakash_singh/theory.txt b/Introduction-to-Data-Science/Session-6/aakash_singh/theory.txt new file mode 100644 index 0000000..06c5b7e --- /dev/null +++ b/Introduction-to-Data-Science/Session-6/aakash_singh/theory.txt @@ -0,0 +1,28 @@ +q1: + Class implements the OOP concept in python. It provides a way to encapsulate all data and methods related to an object into one package. + +q2: + An instance in python is a class object that has all the attributes described in the class definition. + +q3: + A class defines how the object should work and all its attributes. + An instance is the implementation of the class definition in a code. + +q4: + class newClass(inheritClass): + attributes + +q5: + any function that is defined inside the class of the object is called a method of the object. + +q6: + self is a way in python class to refer to the attributes of the object. + This helps segregate method parametres from the object member functions. + +q7: + __init__ is a method which is equivalent to a constructor in c++. + __init__ is called whenever a new object of the class is formed and it initializes the object. + +q8: + the derived class inherits from a base class. In this process the the attributes of the base class are available to the object of the derived class. + This prevents code duplication and encourages code reuse. \ No newline at end of file