-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/linrakesh/python
- Loading branch information
Showing
33 changed files
with
710 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=" ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.