Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session6 #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Introduction-to-Data-Science/Session-6/aakash_singh/q10.py
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions Introduction-to-Data-Science/Session-6/aakash_singh/q9.py
Original file line number Diff line number Diff line change
@@ -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))
28 changes: 28 additions & 0 deletions Introduction-to-Data-Science/Session-6/aakash_singh/theory.txt
Original file line number Diff line number Diff line change
@@ -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.