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

Assignment4 added #80

Open
wants to merge 5 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
56 changes: 56 additions & 0 deletions Introduction-to-Data-Science/Week-3/Madhuparna/Assignment4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Q1:
Solution:
ab+ mode is for append and open or creat binary file for updating ans reading and writing
at the end of the file.

Q2:
Solution:
When a file is read the data is transferred to a buffer.
Instead of accessing the file from where it is saved which might
take a longer time it is better to load the file in a buffer in memory.
While opening a file a negative value of buffer refers to default buffer size,
while zero indicates no buffering.

Q3:
Solution:
a) try:
file=open("hh.txt","r")
file.readline()
except:
print("Could not open")

b)
try:
a=a+10
except:
print("Name 'a' not defined")

Q4:
Solution:
code:

import os
f=open("nn.txt","w+")
print(f.name)
f.write("Hello\n File Handling \n in Python\n")
f.close()
f=open("nn.txt","r+")
s=f.readlines()
print(s)
s.reverse()

f.close()
f=open("nn.txt","w+")
for item in s:
f.write(item)
f.close()
f=open("nn.txt","r+")
print(f.readlines())
f.close()


Output:
nn.txt
['Hello\n', ' File Handling \n', ' in Python\n']
[' in Python\n', ' File Handling \n', 'Hello\n']
114 changes: 114 additions & 0 deletions Introduction-to-Data-Science/Week-3/Madhuparna/Assignment5.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
Question1:
Solution:
A class is a code template for creating objects.
Objects have member variables and have behaviour associated with them.

Question2:
Solution:
A variable of class type which has all its attributes is called an object.

Question3:
Solution:
A class defines the properties and behavior for the objects represented by the abstraction.
Abstraction is a property of object oriented programming. It denotes the essential properties
and behaviors of an object. It hides code and data. A class thus denotes a category of objects
and act as a blueprint for creating such objects.
An object exhibits the property and behaviors defined by its class.

Question4:
Solution:
Syntax:
class NEWCLASS:
def printhello(self):
print(hello)

Question 5:
Solution:
A method is a function that takes a class instance as its first parameter.
Methods are members of classes.
eg. printhello(self) is a method.

Question6:
Solution:
Self refers to the object whose method was called.

Question7:
Solution:
__init__ is a constructor.It is autoatically called when an object
of the class is created.

Question8:
Solution:
When a class inherits from another class , it's object can access methods from
the inherited class also.
Thus we need not write methods again for the inheriting class.


Question 9:
Solution:
import random
import numpy as np
class deck_of_card:

class card:
def __init__(self,suit,num):
self.suit=suit
self.num=num
cards = []
def __init__(self):
for i in range(13):
self.cards.append(self.card('ace',i))

for i in range(13):
self.cards.append(self.card('heart',i))
for i in range(13):
self.cards.append(self.card('diamond',i))
for i in range(13):
self.cards.append(self.card('club',i))
print(len(self.cards))
print(self.cards[51].suit)
def deal(self,suit,num):
i=0
for i in range(51):

if self.cards[i].suit==suit and self.cards[i].num == num:
del self.cards[i]
def shuffle(self):
if (len(self.cards))==52:
random.shuffle(self.cards)
for i in range(52):
print(self.cards[i].suit, self.cards[i].num)
else:
print('All cards are not there',len(self.cards))

Question 10:
Solution:
class person:
def __init__(self,first='',last='',phno='',el=[]):
self.first_name=first
self.last_name=last
self.phone_num=phno
self.email=el
def cont(self):
print(self.first_name)
print(self.last_name)
print(self.phone_num)
print(self.email)

class address_book:
def __init__(self):
self.adbook=[]
def add_contact(self,f,l,ph,em):
self.adbook.append(person(f,l,ph,em))
def look_up_contact(self,l,f=''):
for i in range(len(self.adbook)):
if self.adbook[i].last_name==l:
print(self.adbook[i].cont());

a=address_book()
a.add_contact('madhu','parna',6888,'[email protected]')
a.look_up_contact('parna')




Loading