Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
linrakesh committed May 9, 2020
1 parent 7cf0732 commit b8b6db5
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 89 deletions.
39 changes: 18 additions & 21 deletions DataStructure/binary_search.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
def binary_search(x, first, last, data):
if(first > last):
return 0
else:
mid = (first+last)//2
if(x[mid] == data):
return 1
if(x[mid] < data):
return binary_search(x, mid+1, last, data)
if(x[mid] > data):
return binary_search(x, first, mid-1, data)


x = [1, 2, 3, 5, 7, 8, 9, 10, 12, 14, 15, 18, 20, 22]
data = 10
data = 15
first = 0
last = 13

# bad way to find data in tuple
''' found =0
first=0
last =13
while (first<=last and found ==0):
mid = int((first+last)/2)
# print(mid)
if(x[mid]==data):
found =1
if(x[mid]<data):
first=mid+1
if(x[mid]>data):
last = mid-1
if(found ==0):
result = binary_search(x, first, last, data)
if(result == 0):
print("Data not found")
else:
print("Data found")
'''
if data in x:
print("Data found")
else:
print("Not found")
22 changes: 9 additions & 13 deletions DataStructure/linear_search.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@

#wrong way to find data
x =[1,2,3,5,7,89,3,62,34,13,5,7,9]
# wrong way to find data
x = [1, 2, 3, 5, 7, 89, 3, 62, 34, 13, 5, 7, 9]
data = 89
''' found =0
found = 0

for i in x:
if i ==data:
found =1
if(found ==0):
print("Data not found")
else:
print("Data found") '''
if i == data:
found = 1

# good way to search data in python
if data in x:
print('found')
if(found == 0):
print("Data not found")
else:
print('not found')
print("Data found")
1 change: 1 addition & 0 deletions DataStructure/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
4 changes: 4 additions & 0 deletions database/12CS/dflsdjfhjas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def (n=20, o=30):
a = n*o
return a
print(a)
2 changes: 1 addition & 1 deletion database/12CS/insert_row.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MySQLdb
db = MySQLdb.connect('localhost', 'root', '', 'davschool')
cursor = db.cursor()
cursor.execute('insert into games values (6,"Python fun")')
cursor.execute('insert into games values (7,"fun with class xii")')
db.close()
print('Record added successfully')
2 changes: 1 addition & 1 deletion database/12CS/select_single_word.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MySQLdb
db = MySQLdb.connect('localhost', 'root', '', 'davschool')
cursor = db.cursor()
cursor.execute('select gname from games where id=6')
cursor.execute('select gname from games where id=5')
game_name = cursor.fetchone()
print('Your Game is :', game_name)
db.close()
10 changes: 1 addition & 9 deletions database/12CS/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
import MySQLdb
db = MySQLdb.connect('localhost', 'root', '', 'davschool')
cursor = db.cursor()
cursor.execute('select id,gname from games where id=6')
game_name = cursor.fetchone()
print('Your Game is :', game_name)
print('Game Id :', game_name[0])
print('Game name :', game_name[1])
db.close()
game_name
2 changes: 1 addition & 1 deletion database/12CS/update_record.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MySQLdb
db = MySQLdb.connect('localhost', 'root', '', 'davschool')
cursor = db.cursor()
cursor.execute('update games set gname ="fun with python " where id=6')
cursor.execute('update games set gname ="fun with rakesh " where id=5')
db.close()
print('Record updated successfully')
12 changes: 6 additions & 6 deletions functions/recursion/fibonacci.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# program to find out nth fibonacci number using recursion
# made by : rakesh kumar
# last compiled : 20-12-2018
# last compiled : 20-12-2018


def fibonacci(n):
if(n==1):
if(n == 1):
return 0
elif(n==2):
elif(n == 2):
return 1
else:
return fibonacci(n-1)+fibonacci(n-2)

if __name__ == "__main__":
for x in range(1,21):
print(fibonacci(x),end=" ")

result = fibonacci(30)
print(result)
6 changes: 5 additions & 1 deletion functions/recursion/natutal_no.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# recursive function to print first 100 natural number
# made by : rakesh kumar


def natural(n):
if n == 100:
print(100, end=" ")
Expand All @@ -8,4 +12,4 @@ def natural(n):


# function call to print 100 natural no
natural(1)
natural(10) #
14 changes: 8 additions & 6 deletions functions/recursion/power.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
def xpower(x,y):
if y ==1 :

def xpower(x, y):
if y == 1:
return x
else:
return (x*xpower(x,y-1))
return (x*xpower(x, y-1))


x = int(input("Enter x : "))
y = int (input("Enter y : "))
result = xpower(x,y)
y = int(input("Enter y : "))
result = xpower(x, y)

print("\n\n {} power {} is {} ".format(x,y,result))
print("\n\n {} power {} is {} ".format(x, y, result))
18 changes: 18 additions & 0 deletions functions/recursion/recursive_linear_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def Linear_Search(l, start, n, value):
if start < n:
if l[start] == value:
return 1
else:
return Linear_Search(l, start+1, n, value)
else:
return 0


l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
data = int(input('Enter number to search :'))
n = len(l)-1
result = Linear_Search(l, 0, n, data)
if(result == 1):
print('data found')
else:
print('Data not not found')
15 changes: 10 additions & 5 deletions functions/recursion/sum_digit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
def sum(n):
if n ==0:
# recursive function to find out sum of digits
# made by : rakesh kumar


def summ(n):
if n == 0:
return 0
else:
return(n%10+sum(n//10))
return(n % 10+summ(n//10)) # 5 + 2 + 1+0


n = int(input("Enter x : "))
result = sum(n)
print("Sum of digits : ",result)
result = summ(n)
print("Sum of digits : ", result)
10 changes: 1 addition & 9 deletions functions/recursion/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
def sum(n):
if n ==0:
return 0
else:
return(n%10+sum(n//10))

n = int(input("Enter x : "))
result = sum(n)
print("Sum of digits : ",result)
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
24 changes: 14 additions & 10 deletions pdf_spilter.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Name: pdf spiller
# Purpose: split pdf in to single pages
# Author: acer
## Created: 13-04-2018
# Created: 13-04-2018
# Copyright: (c) acer 2018
# Licence: <your licence>
#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
import os
import sys # module for terminating
import glob #
import sys # module for terminating
import glob #
import tkinter as tk
from tkinter import filedialog
from PyPDF2 import PdfFileReader, PdfFileWriter
def pdf_splitter(path,dest):


def pdf_splitter(path, dest):
fname = os.path.splitext(os.path.basename(path))[0]
pdf = PdfFileReader(path)
for page in range(pdf.getNumPages()):
pdf_writer = PdfFileWriter()
pdf_writer.addPage(pdf.getPage(page))
output_filename = os.path.join(dest,'{}_page_{}.pdf'.format(fname, page+1))
#print(output_filename)
output_filename = os.path.join(
dest, '{}_page_{}.pdf'.format(fname, page+1))
# print(output_filename)
with open(output_filename, 'wb') as out:
pdf_writer.write(out)
print('Created: {}'.format(output_filename))


if __name__ == '__main__':
#path = "Computer_Science.pdf"
root = tk.Tk()
root.withdraw()
path = filedialog.askopenfilename() #source file name
path = filedialog.askopenfilename() # source file name
dest = filedialog.askdirectory() # destination folder
pdf_splitter(path,dest)
pdf_splitter(path, dest)
7 changes: 1 addition & 6 deletions webscraper/youtubeDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@
# import shutil
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
<<<<<<< HEAD
ydl.download(['https://www.youtube.com/watch?v=wF_B_aagLfI'])
=======
ydl.download(
['https://www.youtube.com/watch?v=SCoGwHCNXVw'])
>>>>>>> 4862d6baee53c91054712373dd7190e101b83a22
ydl.download(['https://youtu.be/GkMnqTnjImk'])

0 comments on commit b8b6db5

Please sign in to comment.