diff --git a/Built-In-Module/math_module.py b/Built-In-Module/math_module.py index 1806822..f25cb4f 100644 --- a/Built-In-Module/math_module.py +++ b/Built-In-Module/math_module.py @@ -1,5 +1,5 @@ import math as m -from mathmatics_operation import add,sub +from mathmatics_operation import Mathmatics as mt print(f"Square Root: ",m.sqrt(25)) print("Ceil :",m.ceil(3.1)) @@ -7,5 +7,5 @@ print("Factorial :", m.factorial(6)) print("Power :",m.pow(3,3)) print("Reminder:",m.remainder(10,3)) -print("Addition",add(2,3)) -print("Substraction",sub(5,3)) \ No newline at end of file +print("Addition",mt.add(2,3)) +print("Substraction",mt.sub(5,3)) \ No newline at end of file diff --git a/Built-In-Module/math_module_builtin.py b/Built-In-Module/math_module_builtin.py new file mode 100644 index 0000000..4d8a3ba --- /dev/null +++ b/Built-In-Module/math_module_builtin.py @@ -0,0 +1,9 @@ +import math + +print("Calculate Power",math.pow(2,3)) +print("Check Reminder",math.remainder(10,3)) +print("Factorial of number",math.factorial(6)) +print("Truncate decimal value",math.trunc(2.3)) +#num="ser" +#print("Is number?",math.isnan(num)) +print("Calculate Square Root",math.sqrt(25)) diff --git a/Built-In-Module/mathmatics_operation.py b/Built-In-Module/mathmatics_operation.py index 12907a2..084bb30 100644 --- a/Built-In-Module/mathmatics_operation.py +++ b/Built-In-Module/mathmatics_operation.py @@ -1,12 +1,17 @@ -def add (number1,number2): - return number1 + number2 +class Mathmatics: + @staticmethod + def add (number1,number2): + return number1 + number2 -def sub (number1,number2): - return number1 - number2 + @staticmethod + def sub (number1,number2): + return number1 - number2 -def div (number1,number2): - return number1 / number2 + @staticmethod + def div (number1,number2): + return number1 / number2 -def mul (number1,number2): - return number1 / number2 + @staticmethod + def mul (number1,number2): + return number1 / number2 diff --git a/Collection/dict.py b/Collection/dict.py new file mode 100644 index 0000000..f33391b --- /dev/null +++ b/Collection/dict.py @@ -0,0 +1,15 @@ +variable_name={ + "name":"Subir", + "surname":"shah", + "address":"pune", +} +print(type(variable_name)) +print(variable_name['name'],variable_name['surname']) +variable_name['name']="Avishek" +print(variable_name) +print(variable_name.keys()) +print(variable_name.values()) +print(variable_name.get("name")) +print(variable_name.items()) + +print(variable_name) \ No newline at end of file diff --git a/Collection/list.py b/Collection/list.py new file mode 100644 index 0000000..268a20e --- /dev/null +++ b/Collection/list.py @@ -0,0 +1,52 @@ +''' +string_list=["Subir","Gitanjali","Avishek","Subir"] +print(string_list) +print(string_list[1]) +string_list[1]="Ranjiv" +print(string_list) +#check lenght of list +print(len(string_list)) +print(type(string_list)) + +surname=["shah","varma","sharma"] +concati=string_list+surname +print(concati) + +a=string_list.append(surname) +print(string_list) +print(string_list[3]) +print(string_list[4][2]) +print(string_list[1:4]) + +if "Avishek" in string_list: + print("Yes") +else: + print("Not Present") + +if "shah" in string_list[4]: + print("Yes") +else: + print("Not Present") +''' + +fruit=["Banana","Apple","Cherry","Papaya","Banana"] +print("Banana Occurance ",fruit.count("Banana")) +fruit.remove("Banana") +fruit.remove("Banana") +print("Remove Banana from list",fruit) +fruit.pop(1) +print("pop 1st element from list",fruit) +fruit.clear() +print("Clear list",fruit) +fruit=["Banana","Apple","Cherry","Papaya","Banana"] +fruit.reverse() +print("Reverse List :",fruit) +fruit.sort() +print("Sorting",fruit) + +for f in fruit: + if f == "Apple": + print(f) + +fruit.insert(1,"Watermelon") +print(fruit) \ No newline at end of file diff --git a/Collection/set.py b/Collection/set.py new file mode 100644 index 0000000..4b9867c --- /dev/null +++ b/Collection/set.py @@ -0,0 +1,11 @@ +from Collection.list import fruit + +number={1,2,3,4,4} +print(number) +number.add(5) +print(number) +number.remove(5) +print(number) +fruit1= {"Banana","Apple","Papaya","Mango","Banana",1,2,3} +print(fruit1) +print(fruit1) \ No newline at end of file diff --git a/Collection/tuple.py b/Collection/tuple.py new file mode 100644 index 0000000..3f8b545 --- /dev/null +++ b/Collection/tuple.py @@ -0,0 +1,5 @@ +fruit=("Banana","Apple","Papaya","Mango","Banana") +fruit1=("Banana","Apple","Papaya","Mango","Banana") + +print(fruit) +print(fruit.count("Banana")) \ No newline at end of file diff --git a/Exception_Handling/exception.py b/Exception_Handling/exception.py new file mode 100644 index 0000000..45279c5 --- /dev/null +++ b/Exception_Handling/exception.py @@ -0,0 +1,19 @@ +#number=10 +#print(number/0) + + +try: + file_name=open("xvz.txt","w") + file_name.read() +except ZeroDivisionError as e: + print("Zero Division Error: {0}".format(e)) +except ValueError as e: + print("Value Error Exception: {0}".format(e)) +except FileNotFoundError as e: + print("File not Present Exception: {0}".format(e)) +except Exception as e: + print("Unknown Error because: {0}".format(e)) +finally: + file_name.close() + +print("This is we have to print") diff --git a/Exception_Handling/user_defined.py b/Exception_Handling/user_defined.py new file mode 100644 index 0000000..065c354 --- /dev/null +++ b/Exception_Handling/user_defined.py @@ -0,0 +1,18 @@ +class ElectionError(Exception): + pass + +def check_eligibility(age): + if int(age) > 18: + return True + else: + raise ElectionError("Person is not Eligible for creating election Card") + +if __name__ == '__main__': + age=input("Enter your Age?") + try: + if check_eligibility(age): + print("Person is Eligible") + except Exception as e: + print(e) + + diff --git a/OOPs/Encapsulation.py b/OOPs/Encapsulation.py index ea4e4cc..f81f40d 100644 --- a/OOPs/Encapsulation.py +++ b/OOPs/Encapsulation.py @@ -18,6 +18,10 @@ def show_detail(self): f=Mango("Mango","Yello","Summer","Hapus") +print(f.name) +print(f._color) +print(f.get_season()) +print(f.type) print(f.show_detail()) diff --git a/ObjectOrientedProgrammin/Bank.py b/ObjectOrientedProgrammin/Bank.py new file mode 100644 index 0000000..52cc10b --- /dev/null +++ b/ObjectOrientedProgrammin/Bank.py @@ -0,0 +1,31 @@ +class Bank: + def __init__(self): + self.branch_code = None + self.branch_name = None + self.branch_address = None + ''' + def __init__(self,branch_code,branch_name, branch_address): + self.branch_code=branch_code + self.branch_name=branch_name + self.branch_address=branch_address + ''' + def set_bank_information(self,branch_code,branch_name,branch_address): + self.branch_code = branch_code + self.branch_name = branch_name + self.branch_address = branch_address + + def get_bank_information(self): + return self.branch_code,self.branch_name,self.branch_address + + +def get_bank_information(): + return get_bank_information() + +#sbi=Bank("SBIN1234","SBI FC Road","Sivaji Nagar, Pune") +sbi=Bank() +sbi.set_bank_information("SBIN1234","SBI FC Road","Sivaji Nagar, Pune") +#sbi.__init__("SBIN1234","SBI FC Road","Sivaji Nagar, Pune") +print(sbi.get_bank_information()) +print("Branch Name : ",sbi.branch_name) + + diff --git a/ObjectOrientedProgrammin/abstraction.py b/ObjectOrientedProgrammin/abstraction.py new file mode 100644 index 0000000..8e6cfe0 --- /dev/null +++ b/ObjectOrientedProgrammin/abstraction.py @@ -0,0 +1,22 @@ +from abc import abstractmethod,ABC + +class Car(ABC): + @abstractmethod + def start(self): + pass + + def engine(self): + print("Starting Engine") + +class ElectricVehical(Car): + def start(self): + print("Starting Electric Vehicle") + + + '''def engine(self): + print("Starting Engine from Elctric Vehicle class") +''' + +elctric=ElectricVehical() +#elctric.engine() +elctric.start() \ No newline at end of file diff --git a/ObjectOrientedProgrammin/customer.py b/ObjectOrientedProgrammin/customer.py new file mode 100644 index 0000000..321fcf8 --- /dev/null +++ b/ObjectOrientedProgrammin/customer.py @@ -0,0 +1,6 @@ +from ObjectOrientedProgrammin import Bank +sbi=Bank() +sbi.set_bank_information("SBIN1234","SBI FC Road","Sivaji Nagar, Pune") +#sbi.__init__("SBIN1234","SBI FC Road","Sivaji Nagar, Pune") +print(sbi.get_bank_information()) +print("Branch Name : ",sbi.branch_name) diff --git a/ObjectOrientedProgrammin/encapsulation.py b/ObjectOrientedProgrammin/encapsulation.py new file mode 100644 index 0000000..b44591a --- /dev/null +++ b/ObjectOrientedProgrammin/encapsulation.py @@ -0,0 +1,34 @@ +class Bank: + def __init__(self,account_number,account_name,account_branch): + self._account_number=account_number #protected + self.__account_name=account_name #private + self.account_branch=account_branch + + def get_account_number(self): + return self._account_number + + def get_account_name(self): + return self.__account_name + + def get_account_branch(self): + return self.account_branch + +class Branch(Bank): + def __init__(self,account_number,account_name,account_branch,branch_address): + Bank.__init__(self,account_number,account_name,account_branch) + self.branch_address=branch_address + + def get_branch_address(self): + return self.branch_address + + def show_all_details(self): + return self._account_number,self.account_branch,self.branch_address,self.get_account_name() + + +branch=Branch("0000001","Ranjiv","Sambhajinagar","BaifRoad Pune") +print(branch._account_number) +#print(branch.get_account_name()) +#print(branch.account_branch) +#print(branch.branch_address) + +print(branch.show_all_details()) diff --git a/ObjectOrientedProgrammin/multiple_inheritance.py b/ObjectOrientedProgrammin/multiple_inheritance.py new file mode 100644 index 0000000..dcf6b32 --- /dev/null +++ b/ObjectOrientedProgrammin/multiple_inheritance.py @@ -0,0 +1,34 @@ +class Honda: + def __init__(self,company_name,company_address): + self.company_name=company_name + self.company_address=company_address + + def show_company_details(self): + return self.company_name,self.company_address + +class HondaCar(Honda): + def __init__(self,company_name,company_address,car_name): + super().__init__(company_name,company_address) + self.car_name=car_name + + +class HondaBike(): + def __init__(self, bike_name): + #super().__init__(company_name, company_address) + self.bike_name=bike_name + + +class HondaCustomer(HondaCar,HondaBike): + def __init__(self,company_name,company_address,car_name,bike_name,customer_name): + HondaCar.__init__(self,company_name,company_address,car_name) + HondaBike.__init__(self,bike_name) + self.customer_name=customer_name + + def show_all_details(self): + return self.company_name,self.company_address,self.car_name,self.bike_name,self.customer_name + + +hc=HondaCustomer("Honda","Japanese","City Honda","CBZ","Ranjiv") +print(hc.show_all_details()) + + diff --git a/ObjectOrientedProgrammin/polymorphism_method_overloading.py b/ObjectOrientedProgrammin/polymorphism_method_overloading.py new file mode 100644 index 0000000..81f686b --- /dev/null +++ b/ObjectOrientedProgrammin/polymorphism_method_overloading.py @@ -0,0 +1,45 @@ +class Car: + def start_engine(self): + print("Starting Engine of Car") + + def drive(self): + print("This Car is Driving on Road") + + +class Electric(Car): + def start_engine(self): + print("Start Electric Car Engine") + + def drive(self): + print("Driving Electric Car") + +class SportsCar(Car): + def start_engine(self): + print("Start Sports Car Engine") + + def drive(self): + print("Driving Sports Car") + +#Run time polymorphism +def test_runtime(xyz): + xyz.start_engine() + xyz.drive() + +car=Car() +electric=Electric() +sportscar=SportsCar() + +test_runtime(car) +test_runtime(electric) +test_runtime(sportscar) + +''' +electric.start_engine() +electric.drive() + +sportscar.start_engine() +sportscar.drive() + +car.start_engine() +car.drive() +''' \ No newline at end of file diff --git a/ObjectOrientedProgrammin/polymorphism_method_overriding.py b/ObjectOrientedProgrammin/polymorphism_method_overriding.py new file mode 100644 index 0000000..09c4736 --- /dev/null +++ b/ObjectOrientedProgrammin/polymorphism_method_overriding.py @@ -0,0 +1,13 @@ +class Car: + def show_details(self,*args): + if (len(args) == 1): + print("One Arguments has been passed") + elif (len(args) == 2): + print("Two Arguments has been passed") + elif (len(args) == 3): + print("Three Arguments has been passed") + +car=Car() +car.show_details("Hyundai") +car.show_details("Hyundai","Maruti") +car.show_details("Hyundai","Maruti","Wolkwagon") \ No newline at end of file diff --git a/ObjectOrientedProgrammin/single_inheritance.py b/ObjectOrientedProgrammin/single_inheritance.py new file mode 100644 index 0000000..2682b78 --- /dev/null +++ b/ObjectOrientedProgrammin/single_inheritance.py @@ -0,0 +1,53 @@ +class Bank: + def __init__(self,bank_name,bank_headquarter): + self.bank_name=bank_name + self.bank_headquarter=bank_headquarter + + def show_bank(self): + return self.bank_name,self.bank_headquarter + +class SBIBank(Bank): + def __init__(self,bank_name,bank_headquarter,branch_code,branch_name,branch_address): + super().__init__(bank_name,bank_headquarter) + self.branch_code=branch_code + self.branch_name=branch_name + self.branch_address=branch_address + + def branch_info(self): + return self.branch_code,self.branch_name,self.branch_address + + def update_branch_code(self,branch_code): + self.branch_code=branch_code + + +class Branch(SBIBank): + def __init__(self,bank_name,bank_headquarter,branch_code,branch_name,branch_address,account_no, account_name, account_address): + super().__init__(bank_name,bank_headquarter,branch_code,branch_name,branch_address) + self.account_no=account_no + self.account_name=account_name + self.account_address=account_address + + def show_customer_info(self): + return self.branch_code,self.branch_name,self.branch_address,self.account_no, self.account_name, self.account_address + + + +vbranch=Branch("SBIN","Mumbai","SBIN1234","SBIN Viman Nagar","Viman Nagar,Pune","XYZ","Ayush","Aurangabad") +print(vbranch.show_bank()) +sbranch=Branch("AXIS","Pune","AXISNXYZ","AXIS Nariman Point","Mumbai","ABC","Vijay Mallya","London") +print(sbranch.show_bank()) +''' +print(vbranch.branch_info()) +print(vbranch.show_customer_info()) +print(sbranch.branch_info()) +print(sbranch.show_customer_info()) + + +bank=SBIBank("SBIN1234","SBIN Viman Nagar","Viman Nagar,Pune") +bank.update_branch_code("SBINXYZ") +bc,bn,ba=bank.branch_info() + +print("Branch Code is : ",bc) +print("Branch Name is :", bn) +print("Branch Address is :",ba) +''' \ No newline at end of file diff --git a/Operator/operator.py b/Operator/operator.py new file mode 100644 index 0000000..4a96b67 --- /dev/null +++ b/Operator/operator.py @@ -0,0 +1,53 @@ +from devops_oops import student + +number1=2 +number2=23 +name="Subir" +surname="shah" + +print("Addition of two number :",number1+number2) +print("Substraction of two number :",number1-number2) +print("Multiplication of two number :",number1*number2) +print("Division of two number :",number1/number2) +print("MOdulus of two number :",number1%number2) +print("Exponentials :",number1**number2) +print("My full name is :",name +" "+surname) + +if number1 == number2: + print("Both Number are same") + +if number1 != number2: + print("Both Number are not same") + +if number1 > number2: + print("number1 is greater than number2") + + +if number1 < number2: + print("number1 is less than number2") + +choice="Delhi" +salary=10 +if not (choice=="Mumbai" or choice=="Pune") and salary == 10: + print("Process for interview") +else: + print("Rejet the candidates") + +name="Subir" + +if name == "Subir": + print("Same") + +number=10 + +if number is 10: + print("same") + + +text="this is python based program" +if "python" in text: + print("String is present") + +students=["Subir","Gitanjali","Ayush","Avishek"] +if "Ranjiv" not in students: + print("Student is not present in list") \ No newline at end of file diff --git a/Read_Write_File/industry.txt b/Read_Write_File/industry.txt new file mode 100644 index 0000000..1e56a64 --- /dev/null +++ b/Read_Write_File/industry.txt @@ -0,0 +1,48 @@ +Industry +Accounting/Finance +Advertising/Public Relations +Aerospace/Aviation +Arts/Entertainment/Publishing +Automotive +Banking/Mortgage +Business Development +Business Opportunity +Clerical/Administrative +Construction/Facilities +Consumer Goods +Customer Service +Education/Training +Energy/Utilities +Engineering +Government/Military +Green +Healthcare +Hospitality/Travel +Human Resources +Installation/Maintenance +Insurance +Internet +Job Search Aids +Law Enforcement/Security +Legal +Management/Executive +Manufacturing/Operations +Marketing +Non-Profit/Volunteer +Pharmaceutical/Biotech +Professional Services +QA/Quality Control +Business Software +Business Edtech +Real Estate +Restaurant/Food Service +Retail +Sales +Science/Research +Skilled Labor +Technology +Telecommunications +Transportation/Logistics +Other +tech Business +indus Business \ No newline at end of file diff --git a/Read_Write_File/os_module.py b/Read_Write_File/os_module.py new file mode 100644 index 0000000..b81bca6 --- /dev/null +++ b/Read_Write_File/os_module.py @@ -0,0 +1,22 @@ +import os + + +working_dir=os.getcwd() +print(working_dir) +#os.remove(working_dir+"/new_file") +#os.remove(working_dir+"/writable.txt") + + +print(os.path.exists("prefered.txt")) +os.rmdir("dummy") + + +#Take a input for a multiple students +#write data into text file +name,marks +Ranjiv,90 +Mahesh,40 +Ayush,60 +Gitanjali,75 +Ajay,89 +#Read the file and display students who score more than 75 marks \ No newline at end of file diff --git a/Read_Write_File/read_text.py b/Read_Write_File/read_text.py new file mode 100644 index 0000000..314ed1c --- /dev/null +++ b/Read_Write_File/read_text.py @@ -0,0 +1,36 @@ +''' + +with open("industry.txt") as file_o: + content=file_o.read() + print(content) + file_o.close() + +with open("industry.txt","r") as file_obj: + for line in file_obj: + if line.strip() in ["Automotive","Banking/Mortgage","Clerical/Administrative"]: + print(line) + file_obj.close() + +with open("industry.txt") as file_obj: + print(file_obj.readable()) + file_obj.close() + +''' +with open("industry.txt") as file_obj: + print(file_obj.readlines()) + print("is file writable or not",file_obj.writable()) + print("if file readable or not",file_obj.readable()) +''' +with open("industry.txt") as file_obj: + print(file_obj.readlines()[2:10]) + file_obj.close() + +list_obj=[] +with open("industry.txt", "r") as file_obj: + for line in file_obj: + list_obj.append(line) + + file_obj.close() + +print(list_obj) +''' \ No newline at end of file diff --git a/Read_Write_File/write.py b/Read_Write_File/write.py new file mode 100644 index 0000000..b479640 --- /dev/null +++ b/Read_Write_File/write.py @@ -0,0 +1,33 @@ +''' +with open("industry.txt") as read_obj: + with open("prefered_industry.txt","w") as write_obj: + for line in read_obj: + if "Business" in line: + write_obj.write(line) + +write_obj.close() +read_obj.close() +''' + +''' +with open("industry.txt") as read_obj: + with open("writable.txt","w") as write_obj: + write_obj.writelines(read_obj.readlines()) + + +with open("new_file","a") as write_obj: + students=["Ajay\n","Ranjiv\n","Gitanjali\n","Mahesh\n"] + write_obj.writelines(students) + +with open("new_file","a") as write_obj: + students=["Ajay\n","Ranjiv\n","Gitanjali\n","Mahesh\n"] + for student in students: + write_obj.write(student) + +''' +with open("industry.txt") as read_obj: + with open("writable.txt","a") as write_obj: + write_obj.write("\n") + for line in read_obj: + if "Business" in line: + write_obj.write(line) diff --git a/String_Method/string_method.py b/String_Method/string_method.py new file mode 100644 index 0000000..13961d3 --- /dev/null +++ b/String_Method/string_method.py @@ -0,0 +1,41 @@ +from Method_Overriding import test_drive +from devops_operator import names + +text="this is python based program" +number=" " + +print("Check is Lower :",text.islower()) +print("Check the string is digit : ",text.isdigit()) +print("Check the string is digit : ",number.isdigit()) +print("Check string is numeric :",number.isnumeric()) +print("Check string is Alpha :", text.isalpha()) +print("Check string is Alphnumeric :", text.isalnum()) +print("Check if space is there ?", number.isspace()) + +''' +name=input("Enter your name ?") +if name.isspace(): + print("Enter Valid name") +else: + print("This name has been entered :", name) +''' + +print("Check number of times string present :",text.count("python")) + +if text.islower(): + print("This is lower case text") +else: + print("It contains upper case character") + +print(text.capitalize()) + +print(text.find("python")) + +print(text.upper()) +print(text.lower()) + +print(text.replace("python","java")) +print(len(text)) + +print(text.split(" ")) + diff --git a/Threading/duration b/Threading/duration new file mode 100644 index 0000000..d08915c --- /dev/null +++ b/Threading/duration @@ -0,0 +1,7 @@ +1 Process execution timing + +time python normal_example.py + +real 0m0.061s +user 0m0.000s +sys 0m0.015s diff --git a/Threading/normal_example.py b/Threading/normal_example.py new file mode 100644 index 0000000..e82de4a --- /dev/null +++ b/Threading/normal_example.py @@ -0,0 +1,14 @@ +try: + for num in range(3): + filename="read"+str(num)+".txt" + with open(filename,"r") as read_file: + with open("write.txt","a") as write_file: + read_lines=read_file.readlines() + for line in read_lines: + write_file.write(str(num) + "-" + line) + + write_file.close() + read_file.close() + +except Exception as e: + print("Error in Reading and Writing file : {0}".format(e)) diff --git a/Threading/prevent_race_conditon.py b/Threading/prevent_race_conditon.py new file mode 100644 index 0000000..cf29c64 --- /dev/null +++ b/Threading/prevent_race_conditon.py @@ -0,0 +1,26 @@ +import threading +import time +import random + +def read_write(read_file,write_file,thread,lock): + with lock: + with open(read_file,"r") as read_file1: + with open(write_file,"a") as write_file1: + read_lines=read_file1.readlines() + for line in read_lines: + time.sleep(0.1) + write_file1.write("Thread -" + str(thread) + "----" + line) + +if __name__ == '__main__': + thread_list=[] + for num in range(3): + lock = threading.Lock() + read_file_name="read"+str(num)+".txt" + t = threading.Thread(target=read_write, args=(read_file_name, "write.txt", str(num),lock)) + thread_list.append(t) + + for thread in thread_list: + thread.start() + + for thread1 in thread_list: + thread1.join(1000) diff --git a/Threading/read0.txt b/Threading/read0.txt new file mode 100644 index 0000000..61c0b76 --- /dev/null +++ b/Threading/read0.txt @@ -0,0 +1,6 @@ +This is number : 0 +This is number : 1 +This is number : 2 +This is number : 3 +This is number : 4 +This is number : 5 \ No newline at end of file diff --git a/Threading/read1.txt b/Threading/read1.txt new file mode 100644 index 0000000..61c0b76 --- /dev/null +++ b/Threading/read1.txt @@ -0,0 +1,6 @@ +This is number : 0 +This is number : 1 +This is number : 2 +This is number : 3 +This is number : 4 +This is number : 5 \ No newline at end of file diff --git a/Threading/read2.txt b/Threading/read2.txt new file mode 100644 index 0000000..61c0b76 --- /dev/null +++ b/Threading/read2.txt @@ -0,0 +1,6 @@ +This is number : 0 +This is number : 1 +This is number : 2 +This is number : 3 +This is number : 4 +This is number : 5 \ No newline at end of file diff --git a/Threading/simulate.py b/Threading/simulate.py new file mode 100644 index 0000000..a31b5e1 --- /dev/null +++ b/Threading/simulate.py @@ -0,0 +1,23 @@ +import threading +import time +import random + +lock=threading.Lock() +def write_data(thread_name): + for i in range(5): + time.sleep(0.1) + with lock: + print(f"Thread : {thread_name} Writing Data") + +if __name__ == '__main__': + thread_list=[] + for num in range(3): + t = threading.Thread(target=write_data, args=(str(num))) + thread_list.append(t) + + for thread in thread_list: + thread.start() + + for thread1 in thread_list: + thread1.join(1000) + diff --git a/Threading/threading_example.py b/Threading/threading_example.py new file mode 100644 index 0000000..5903f37 --- /dev/null +++ b/Threading/threading_example.py @@ -0,0 +1,24 @@ +import threading +import time +import random + +def read_write(read_file,write_file,thread): + with open(read_file,"r") as read_file1: + with open(write_file,"a") as write_file1: + read_lines=read_file1.readlines() + for line in read_lines: + write_file1.write("Thread -" + str(thread) + "----" + line) + + +if __name__ == '__main__': + thread_list=[] + for num in range(3): + read_file_name="read"+str(num)+".txt" + t = threading.Thread(target=read_write, args=(read_file_name, "write.txt", str(num))) + thread_list.append(t) + + for thread in thread_list: + thread.start() + + for thread in thread_list: + thread.join() diff --git a/Threading_Example/number.txt b/Threading_Example/number.txt index 7c8515e..cb0fea6 100644 --- a/Threading_Example/number.txt +++ b/Threading_Example/number.txt @@ -98,4 +98,66 @@ This is number : 96 This is number : 97 This is number : 98 - This is number : 99 \ No newline at end of file + This is number : 99 + This is number : 0 + This is number : 1 + This is number : 2 + This is number : 3 + This is number : 4 + This is number : 5 + This is number : 6 + This is number : 7 + This is number : 8 + This is number : 9 + This is number : 10 + This is number : 11 + This is number : 12 + This is number : 13 + This is number : 14 + This is number : 15 + This is number : 16 + This is number : 17 + This is number : 18 + This is number : 19 + This is number : 20 + This is number : 21 + This is number : 22 + This is number : 23 + This is number : 24 + This is number : 25 + This is number : 26 + This is number : 27 + This is number : 28 + This is number : 29 + This is number : 30 + This is number : 31 + This is number : 32 + This is number : 33 + This is number : 34 + This is number : 35 + This is number : 36 + This is number : 37 + This is number : 38 + This is number : 39 + This is number : 40 + This is number : 41 + This is number : 42 + This is number : 43 + This is number : 44 + This is number : 45 + This is number : 46 + This is number : 47 + This is number : 48 + This is number : 49 + This is number : 50 + This is number : 51 + This is number : 52 + This is number : 53 + This is number : 54 + This is number : 55 + This is number : 56 + This is number : 57 + This is number : 58 + This is number : 59 + This is number : 60 + This is number : 61 \ No newline at end of file diff --git a/Threading_Example/threading_file.py b/Threading_Example/threading_file.py new file mode 100644 index 0000000..236e542 --- /dev/null +++ b/Threading_Example/threading_file.py @@ -0,0 +1,29 @@ +import threading +from time import sleep + + +def file_read_write(read_file_name,write_file_name,thread): + try: + with open(read_file_name,"r") as file_read: + with open(write_file_name,"a") as file_write: + read_text=file_read.readlines() + for read in read_text: + sleep(1) + file_write.write(thread + "-" + read) + + except Exception as e: + print("Error in Reading and Writting file : {0}".format(e)) + +if __name__ == '__main__': + thread_list=[] + for num in range(4): + file_name="number"+str(num)+".txt" + print(file_name) + thread=threading.Thread(target=file_read_write,args=(str(file_name),"write_file.txt",str(num))) + thread_list.append(thread) + + for num in thread_list: + num.start() + + for num in thread_list: + num.join() \ No newline at end of file diff --git a/conditional_looping/__init__ b/conditional_looping/__init__ new file mode 100644 index 0000000..e69de29 diff --git a/conditional_looping/for_loop.py b/conditional_looping/for_loop.py new file mode 100644 index 0000000..07afa02 --- /dev/null +++ b/conditional_looping/for_loop.py @@ -0,0 +1,42 @@ +''' +#for loop syntax +for iterator in + statement +''' +from random import random + +from Operator.operator import students + +fruit= {"Banana","Apple","Orange","Papaya","Mango"} + +for f in fruit: + if f in ["Banana","Apple"]: + print("This is Winter season fruit", f) + elif f in ["Mango","Papaya"]: + print("This is Summer season fruit", f) + elif f in ["Orange"]: + print("This is Rainy season fruit", f) + + +for i in range(10): + if i == 5: + continue + print(i) + +student=["Subir","Avishek","Gitanjali","Ranjiv","Ayush"] +for s in student: + if s == "Gitanjali": + print("Performing some action") + break + +''' +1. create a list of numbers +2. check number is odd or even and seperate into two list + +number=[1,10,21,20,30,23,45,68,70,101] + +output + +odd=[1,21,23,45,101] +even=[10,20,30,68,70] +''' \ No newline at end of file diff --git a/conditional_looping/if_elif_else.py b/conditional_looping/if_elif_else.py new file mode 100644 index 0000000..0b7c53f --- /dev/null +++ b/conditional_looping/if_elif_else.py @@ -0,0 +1,51 @@ +'''' +# Check number if odd or even +if : #if condition is satisfied then execute statement + statement +elif : #check if above condition is not match, then chekc this condition if match then execute + statement +else: #if none of condition satisfied then execute else block + statement +''' +''' +#check number if odd or even +number=input("Enter Number : ") +if int(number) % 2 == 0: + print("Number is even") +else: + print("Number is odd") +''' + +#Hire candidates, based on below parameter +#condition 1 - Person should be ready to relocate in Pune or Mumbai Location +#condition 2 - Person salary should not be greater than 30 +#condition 3 - Person experience should be more than 10 years + +location="Delhi" +salary=12 +experience=11 + +if location == "Pune" or location == "Mumbai" and salary < 30 and experience > 10: + print("Process for interview") +else: + print("Reject candidates") + + +#Information about couse +course_name="Python" +crashcourse=False + +if course_name == "Python": + print("Welcome to Python Course") + if crashcourse: + print("Crash course duration 2 month") + else: + print("Full course duration 6 month") +elif course_name == "Devops": + print("Welcome to Devops Course, Course duration is 3+ month") +elif course_name == "Java": + print("Welcome to Java Course, Course duration is 6+ month") +else: + print("We don't have such course available") + +# \ No newline at end of file diff --git a/conditional_looping/while.py b/conditional_looping/while.py new file mode 100644 index 0000000..7fc1b01 --- /dev/null +++ b/conditional_looping/while.py @@ -0,0 +1,17 @@ +''' +#while loop syntax +while : + statement +''' + +number=1 +while True: + if number > 10: + break + print(number) + number = number + 1 + +number=1 +while number <= 10: + print(number) + number=number+1 diff --git a/fetch_data.py b/fetch_data.py new file mode 100644 index 0000000..b875ac4 --- /dev/null +++ b/fetch_data.py @@ -0,0 +1,6 @@ +from user_defined_module.payroll import Payroll as p +try: + print(p.show_salary("00012")) + print(p.insert_salary("00012","10000","12000")) +except Exception as e: + print("Exception triggered :",e) \ No newline at end of file diff --git a/function/use_function.py b/function/use_function.py new file mode 100644 index 0000000..61392f4 --- /dev/null +++ b/function/use_function.py @@ -0,0 +1,7 @@ +from user_defined_function import diffOddEven + +number=[1,10,21,20,30,23,45,68,70,101] +odd_list,even_list=diffOddEven(number) + +print("Odd List :",odd_list) +print("Even List :",even_list) \ No newline at end of file diff --git a/function/user_defined_function.py b/function/user_defined_function.py new file mode 100644 index 0000000..6cffaeb --- /dev/null +++ b/function/user_defined_function.py @@ -0,0 +1,39 @@ +''' +def functionname(,,..): + statement + return + + +return_vaule=functionname(,,..) +''' +''' +#without args +def isodd(number): + if number%2 == 0: + return False + else: + return True + + + +#pass argument concatinate function +def concatinate(string1,string2): + return string1+string2 + +print(concatinate("Ayush","Lakde")) +''' + + +def diffOddEven(num_list): + if len(num_list) == 0: + return None + odd=[] + even=[] + for num in num_list: + if num%2 == 0: + even.append(num) + else: + odd.append(num) + + return odd,even + diff --git a/os_module_buildin.py b/os_module_buildin.py new file mode 100644 index 0000000..cd1ba8c --- /dev/null +++ b/os_module_buildin.py @@ -0,0 +1,19 @@ +import os +import datetime +print("Get Current Working Directory",os.getcwd()) +print("Check file is present",os.path.isfile("student.txt")) +print("Check Environment Variables ",os.environ) +print("Print Environment Variables :",os.environ['HOMEPATH']) +os.environ["SKILL"]="Python" +print("Print Environment Variables :",os.environ['SKILL']) +print("Get Computer Name",os.name) +print("Get Process Id",os.getpid()) +curret_worl=os.getcwd() +log_file="log.txt" +file_path=os.path.join(curret_worl,log_file) +date=datetime.datetime.now() +with open(file_path,"w") as file_write: + file_write.write(f"{date},Writing Logs into file") + + +#print(os.remove("student.txt")) \ No newline at end of file diff --git a/student.txt b/student.txt deleted file mode 100644 index ac4e740..0000000 --- a/student.txt +++ /dev/null @@ -1,2 +0,0 @@ -My Name is Rashmi -My Name is Rashmi diff --git a/use_arithemtic.py b/use_arithemtic.py new file mode 100644 index 0000000..869fa80 --- /dev/null +++ b/use_arithemtic.py @@ -0,0 +1,7 @@ +from user_defined_module.arrithmetic import Arrith as at +number1=10 +number2=20 +print("Addition of Two Numbers",at.add(number1,number2)) +print("Substraction of Two Numbers",at.sub(number1,number2)) +print("Multiplication of Two Numbers",at.mul(number1,number2)) +print("Divition of Two Numbers",at.div(number1,number2)) diff --git a/user_defined_module/arrithmetic.py b/user_defined_module/arrithmetic.py new file mode 100644 index 0000000..4d8b384 --- /dev/null +++ b/user_defined_module/arrithmetic.py @@ -0,0 +1,20 @@ +class Arrith: + + @staticmethod + def add(number1,number2): + return number1+number2 + + @staticmethod + def sub(number1,number2): + return number1-number2 + + @staticmethod + def div(number1,number2): + return number1/number2 + + @staticmethod + def mul(number1,number2): + return number1*number2 + + + diff --git a/user_defined_module/payroll.py b/user_defined_module/payroll.py new file mode 100644 index 0000000..f6816c5 --- /dev/null +++ b/user_defined_module/payroll.py @@ -0,0 +1,32 @@ +class Payroll: + @staticmethod + def show_salary(empid): + # Check this employee id is present in Database + # Fetch Employee salary structure from Database + # Covert into Json + salary = { + "empid": "00012", + "employee_name":"Ayush Lakde", + "employee_address": "Mumbai", + "Basic Salary": "67000", + "Allowance": "120000", + } + return salary + + @staticmethod + def insert_salary(empid,basic_salary,allowance): + # Check this employee id is present in Database + # Fetch Employee Record from Database + #insert salary into Database + salary = { + "empid": empid, + "employee_name":"Ayush Lakde", + "employee_address": "Mumbai", + "Basic Salary": basic_salary, + "Allowance": allowance, + } + success ={ + "return_code":200, + "message": "Employee Data inserted Successfully" + } + return success