Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/linrakesh/python
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed Jan 5, 2020
2 parents 7f45c3f + 89ba938 commit 805b4ad
Show file tree
Hide file tree
Showing 33 changed files with 710 additions and 67 deletions.
8 changes: 8 additions & 0 deletions ExceptionHandling/Try_else.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a = 10
b = int(input("Enter any number "))
try:
c = a/b
except:
print('Cannot divide NUMBER by STRING')
else:
print('Result :', c)
12 changes: 12 additions & 0 deletions Loops/binary_decinal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# program to find out decimal number of any given binary number
# made by : rakesh kumar
n = int(input('Enter any number :'))
sum = 0
i = 0
while n != 0:
rem = n % 10
sum = sum+rem*2**i
n = n//10
i = i+1

print('Decimal Equivalent :', sum)
10 changes: 10 additions & 0 deletions Loops/decimal_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# program to find out binary equivalent of any decimal number
# made by : rakesh kumar

n = int(input('Enter any number :'))
l = ''
while(n != 0):
l = str(n % 2) + l
n = n//2

print(l)
21 changes: 1 addition & 20 deletions Loops/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
# program to find out EMI using formula
# EMI = (p*r(1+r)**t)/((1+r)**t-1)
# made by : rakesh kumar

from math import pow


def emi_calculate(p, r, t):
r = r/(12*100) # rate for one month
t = t*12 # one month time
emi = (p*r*pow(1+r, t))/(pow(1+r, t)-1)
return emi


if __name__ == "__main__":
p = int(input('Enter pricipal amount :'))
r = int(input('Enter rate of interest :'))
t = int(input('Enter time in years :'))
emi = emi_calculate(p, r, t)

print('Monthly Installment :%.2f' % emi)
i = i+1
83 changes: 83 additions & 0 deletions Projects/sudoku_solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
board = [
[7, 8, 0, 4, 0, 0, 1, 2, 0],
[6, 0, 0, 0, 7, 5, 0, 0, 9],
[0, 0, 0, 6, 0, 1, 0, 7, 8],
[0, 0, 7, 0, 4, 0, 2, 6, 0],
[0, 0, 1, 0, 5, 0, 9, 3, 0],
[9, 0, 4, 0, 6, 0, 0, 0, 5],
[0, 7, 0, 3, 0, 0, 0, 1, 2],
[1, 2, 0, 0, 0, 7, 4, 0, 0],
[0, 4, 9, 2, 0, 6, 0, 0, 7]
]


def solve(bo):
find = find_empty(bo)
if not find:
return True
else:
row, col = find

for i in range(1, 10):
if valid(bo, i, (row, col)):
bo[row][col] = i

if solve(bo):
return True

bo[row][col] = 0

return False


def valid(bo, num, pos):
# Check row
for i in range(len(bo[0])):
if bo[pos[0]][i] == num and pos[1] != i:
return False

# Check column
for i in range(len(bo)):
if bo[i][pos[1]] == num and pos[0] != i:
return False

# Check box
box_x = pos[1] // 3
box_y = pos[0] // 3

for i in range(box_y*3, box_y*3 + 3):
for j in range(box_x * 3, box_x*3 + 3):
if bo[i][j] == num and (i, j) != pos:
return False

return True


def print_board(bo):
for i in range(len(bo)):
if i % 3 == 0 and i != 0:
print("- - - - - - - - - - - - - ")

for j in range(len(bo[0])):
if j % 3 == 0 and j != 0:
print(" | ", end="")

if j == 8:
print(bo[i][j])
else:
print(str(bo[i][j]) + " ", end="")


def find_empty(bo):
for i in range(len(bo)):
for j in range(len(bo[0])):
if bo[i][j] == 0:
return (i, j) # row, col

return None


print_board(board)
solve(board)
print("___________________")
print_board(board)
13 changes: 13 additions & 0 deletions autoGUI/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# purpose : Program to check mouse position on the move
# author : rakesh kumar
# licence : MIT
import pyautogui
print("Press CTRL+C to stop")
try:
while True:
x,y = pyautogui.position()
positionStr = "X :"+str(x).rjust(4) +" Y :"+ str(y).rjust(4)
print(positionStr, end='')
print('\b' * len(positionStr), end='', flush=True)
except KeyboardInterrupt:
print("\n Done")
2 changes: 1 addition & 1 deletion fileHandling/Bulk_Image_Resizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def small(source,target,original):
dest = target + '\\' +original
with open(original, 'r+b') as f:
with Image.open(f) as image:
cover = resizeimage.resize_cover(image, [900, 450], validate=False)
cover = resizeimage.resize_cover(image, [960, 640], validate=False)
cover.save(dest, image.format)

def deleteFiles():
Expand Down
22 changes: 13 additions & 9 deletions fileHandling/delete All File with extension_EXE.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
#-------------------------------------------------------------------------------
# Name: Program to delete a particular type of files from selected directory
# -------------------------------------------------------------------------------
# Name: Program to delete a particular type of files from selected directory
#
# Author: rakesh
#
# Created: 05-05-2017
# Copyright: MIT
#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
import os
import sys #module for terminating
import sys # module for terminating
import glob
import tkinter as tk
from tkinter import filedialog


def main():
root = tk.Tk()
root.withdraw()
directory = filedialog.askdirectory() #source folder
count=0
for root, SubFolders , files in os.walk(directory):
directory = filedialog.askdirectory() # source folder
count = 0
for root, SubFolders, files in os.walk(directory):
os.chdir(root)
files = glob.glob('*.exe')
files = glob.glob('*.nef')
# print(files)
for filename in files:
print(filename, 'Deleted')
os.unlink(filename)
count+=1
count += 1
print("Total {} files deleted".format(count))


if __name__ == '__main__':
main()
14 changes: 14 additions & 0 deletions functions/addition_fun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def addition(a, b=0):
return a+b


result = addition(10)
print(result)
result = addition('rakesh', ' You are awesome')
print(result)
result = addition(20, 30.45)
print(result)
result = addition([10, 20, 30], [40, 50, 60])
print(result)
result = addition((10, 20, 30), (40, 50, 60))
print(result)
14 changes: 14 additions & 0 deletions functions/armstrong.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

def armstrong(n):
m = n
sum = 0
while(n != 0):
rem = n % 10
sum += rem**3
n = n//10
return True if sum == m else False


if __name__ == "__main__":
n = int(input('Enter any number :'))
print('ArmStrong Number ' if(armstrong(n)) else 'Not a Arm Strong Number ')
17 changes: 17 additions & 0 deletions functions/armstrong_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

def armstrong(n):
m = n
sum = 0
while(n != 0):
rem = n % 10
sum += rem**3
n = n//10
return True if sum == m else False


if __name__ == "__main__":
n1 = int(input('Enter first value :'))
n2 = int(input('Enter last value :'))
for x in range(n1, n2+1):
if(armstrong(x)):
print(x)
15 changes: 15 additions & 0 deletions functions/check_prime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import math as m


def check_prime(n):
flag = True
for x in range(2, n//2):
if n % x == 0:
flag = False

return flag

if __name__ == "__main__":
n = int(input('Enter any integer number : '))
result = check2_prime(n)
print("Prime Number " if (result) else '"Not prime Number')
14 changes: 8 additions & 6 deletions functions/lambda_function.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#program to define lambda function in python
# program to define lambda function in python

f = lambda x : x**2

#lambda function with map() function
l1=[1,2,4,5,6,7,78,7,4,34,4,14,44,4,4]
result = map(f,l1)
print(result)
def f(x): return x**2


# lambda function with map() function
l1 = [1, 2, 4, 5, 6, 7, 78, 7, 4, 34, 4, 14, 44, 4, 4]
result = list(map(f, l1))
print(result)
12 changes: 12 additions & 0 deletions functions/passing_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def common(l1, l2):
c = list()
for x in l1:
if x in l2:
c.append(x)
return c


l1 = [1, 2, 3, 4, 6, 8, 9]
l2 = [2, 4, 6, 7, 9, 10]

print(common(l1, l2))
12 changes: 12 additions & 0 deletions functions/positional_arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def display(number, msg1="School", msg2="Place"):
print('-----Times :', number, end=" ")
print('-----Message 1 :', msg1*2)
print('-----Message 2 :', msg2)
print('----------------------')


display(2, 'DAV', 'Ghaziabad')
display(5)
display("SpringDales")
display(msg2="Modern", number=3)
display(msg2="Modern", msg1=24, number=3)
16 changes: 16 additions & 0 deletions functions/prime_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from math import sqrt


def prime_number(n):
flag = True
for x in range(2, int(sqrt(n))+1):
if n % x == 0:
flag = False
return flag


if __name__ == "__main__":
if(prime_number(12)):
print('Prime Number')
else:
print('Not a prime Number')
22 changes: 22 additions & 0 deletions functions/prime_number_in_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# program to print the prime numbers between a range of numbers.
# made by : rakesh kumar


def check_prime(n):
flag = True
for x in range(2, n//2):
if n % x == 0:
flag = False

return flag


if __name__ == "__main__":
n1 = int(input('Enter the starting number : '))
n2 = int(input('Enter the Ending number number : '))

print('Prime Number between :')
for x in range(n1, n2+1):
result = check_prime(x)
if result:
print(x, end=" ")
11 changes: 11 additions & 0 deletions functions/python_kwargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# python program to demonstrate the use of kwargs arguments in pyhon
# made by : rakesh kumar


def sum_kwargs(**kwargs):
for x, y in kwargs.items():
print('{} and its valiue {}'.format(x, y))


if __name__ == "__main__":
sum_kwargs(name='rakesh', school='DAV', salary=50000)
19 changes: 6 additions & 13 deletions functions/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# program to find out sum of element of a list using recursion
# made by : rakesh kumar
# program to define lambda function in python


def sum_element(l):
if(len(l) == 1):
return l[0]
else:
value = l.pop()
return value+sum_element(l)
def f(x): return x**2


if __name__ == "__main__":

list1 = [1, 2, 34, 5, 6]
result = sum_element(list1)
print('sum of element :', result)
# lambda function with map() function
l1 = [1, 2, 4, 5, 6, 7, 78, 7, 4, 34, 4, 14, 44, 4, 4]
result = map(f, l1)
print(result)
Loading

0 comments on commit 805b4ad

Please sign in to comment.