diff --git a/Introduction-to-Data-Science/Session-5/ShubhamAgrawal/session 5.txt b/Introduction-to-Data-Science/Session-5/ShubhamAgrawal/session 5.txt new file mode 100644 index 0000000..d09d242 --- /dev/null +++ b/Introduction-to-Data-Science/Session-5/ShubhamAgrawal/session 5.txt @@ -0,0 +1,29 @@ +1. +Opens a file for both appending and reading in binary format. The file pointer is at the +end of the file if the file exists. The file opens in the append mode. If the file does not +exist, it creates a new file for reading and writing. + +2. +Every file when read, transfers data to an intermediate buffer before it +can be accessed by Python, this makes the process faster and reduces the risk of data loss while handling data. + +3. + t=1/0 + file1=open(input("Enter name of the file\n"),'r+') + file1.seek(0,2) + file1.write(t) + except IOError: + print("ERROR Enter valid filename") + except ZeroDivisionError: + print("ERROR can't divide by zero") + else: + print("everything's fine") + file1.close() + +4. +file1=open("to_reverse.txt",'r') +list1=file1.readlines() +list1.reverse() +for item in list1: + print(item,end="") +file1.close() \ No newline at end of file diff --git a/Introduction-to-Data-Science/Week-3/ShubhamAgrawal/Assignment3.txt b/Introduction-to-Data-Science/Week-3/ShubhamAgrawal/Assignment3.txt new file mode 100644 index 0000000..589cf34 --- /dev/null +++ b/Introduction-to-Data-Science/Week-3/ShubhamAgrawal/Assignment3.txt @@ -0,0 +1,50 @@ +1). +Keys must be unique in a dictionary. If there's a duplicate, the last entry with that key is taken. + +2). +it will show an error as sets don't support indexing. + +3). +tuples are immutable, they can't be edited. Therefore pop() won't work here. + +4). +output: {'c', 'h', 'o'} + +5). +code: +def fibonacci(n): + n1=1 + n2=1 + print(1) + print(1) + n3=n1 + n2 + for _ in range(3,n+1): + print(n3) + n1=n2 + n2=n3 + n3=n1 +n2 + +n=int(input('enter n : ')) +if(n==1): + print(1) +elif(n==2): + print(1) + print(1) +else: + fibonacci(n) + +6). +import math #for sqroot +n=int(input('enter n : ')) +sqroot = lambda n: math.sqrt(n) +print(sqroot(n)) + +7). +def sortbyvalue(list_1): + import operator + sorted_list = sorted(list_1.items(), key=operator.itemgetter(1)) + print(sorted_list) + + +list_1={1:3,7:1,2:4,5:2} +sortbyvalue(list_1) diff --git a/Introduction-to-Data-Science/Week-4/Session-5/ShubhamAgrawal/session 5.txt b/Introduction-to-Data-Science/Week-4/Session-5/ShubhamAgrawal/session 5.txt new file mode 100644 index 0000000..d09d242 --- /dev/null +++ b/Introduction-to-Data-Science/Week-4/Session-5/ShubhamAgrawal/session 5.txt @@ -0,0 +1,29 @@ +1. +Opens a file for both appending and reading in binary format. The file pointer is at the +end of the file if the file exists. The file opens in the append mode. If the file does not +exist, it creates a new file for reading and writing. + +2. +Every file when read, transfers data to an intermediate buffer before it +can be accessed by Python, this makes the process faster and reduces the risk of data loss while handling data. + +3. + t=1/0 + file1=open(input("Enter name of the file\n"),'r+') + file1.seek(0,2) + file1.write(t) + except IOError: + print("ERROR Enter valid filename") + except ZeroDivisionError: + print("ERROR can't divide by zero") + else: + print("everything's fine") + file1.close() + +4. +file1=open("to_reverse.txt",'r') +list1=file1.readlines() +list1.reverse() +for item in list1: + print(item,end="") +file1.close() \ No newline at end of file diff --git a/Introduction-to-Data-Science/Week-4/Session-6/ShubhamAgrawal/session 6.txt b/Introduction-to-Data-Science/Week-4/Session-6/ShubhamAgrawal/session 6.txt new file mode 100644 index 0000000..2d31583 --- /dev/null +++ b/Introduction-to-Data-Science/Week-4/Session-6/ShubhamAgrawal/session 6.txt @@ -0,0 +1,80 @@ +1. +A class is a way to bind the data describing an entity and its associate functions together. + +2. +An instance, in object-oriented programming (OOP), is a specific realization of any object. +It is an element of a class which inherits its properties. + +3. +An object is an instance of a class where the class represents the definition of some real-world entity. +A variable of the class type is called an object. + +4. +class CLASSNAME: + + . + . + + +5. +A method is a function that takes a class instance as its first parameter. +Methods are members of classes. + +6. +Use of self helps python differentiate between objects. + +7. +__init__ is a special method in Python classes, it is the constructor method for a class. + +8. +We dont have to define all the attributes and methods in another class again, thus it prevents +redundancy and code duplication + +9. +import random //for shuffle +class card(): + suits={"Hearts":["A","2","3","4","5","6","7","8","9","10","J","Q","K"], + "Diamonds":["A","2","3","4","5","6","7","8","9","10","J","Q","K"], + "Clubs":["A","2","3","4","5","6","7","8","9","10","J","Q","K"], + "Spades":["A","2","3","4","5","6","7","8","9","10","J","Q","K"]} + +class deck_of_cards(card): + def deal(self,card_suit,card_name): + card().suits[card_suit].remove(card_name) + + def shuffle_method(self): + if(len(card().suit["Hearts"])+len(card().suit["Diamonds"])+ + len(card().suit["Clubs"])+len(card().suit["Spades"])==52): + print("Deck complete") + + for i in card().suits: + random.shuffle(card().suits[i]) + +10. +class person(): + def __init__(self,first, last,phone_no, email): + self.firstname = first + self.lastname = last + self.phonenumber = phone_no + self.email = email + +class address_book(person): + add_book[] + def __init__(self,data): + self.add_contact(data) + + def add_contact(self,data): + self.add_book.append(data) + + def lookup_contact(self,last,first = "NULL"): + print("enter last name:") + for i in self.add_book: + if(first=="NULL"): + if(i.last == last): + print(i.firstname,i.lastname,i.phonenumber,i.email) + else: + if(i.firstname==first and i.lastname==last): + print(i.firstname,i.lastname,i.phonenumber,i.email) + + + \ No newline at end of file