├── 2048 └── 2048.py ├── 02-Matplotlib-SubPlots.ipynb ├── About_Python ├── Alarm └── alarm.py ├── ArmstrongNum.py ├── ArmstrongNum └── ArmstrongNum.py ├── BFS tree traversal algorithm.cpp ├── Binary Search in C++.cpp ├── BinaryToDecimal and DecimalToBinary ├── BinaryToDecimal └── DecimalToBinary ├── Binary_Search └── binarySearch.py ├── Breadth_First_Search.py ├── Bubble Sort.C ├── Bubble sort.py ├── Bucket_Sort └── bucket_sort.py ├── Calc.py ├── Calculator.py ├── Categorize Password └── Categorize Password.py ├── Contributor.md ├── CountdownTimer.py ├── Dictionary.py ├── Digital clock.py ├── Digital_Signal_Processing └── dsp.ipynb ├── Factorial.py ├── Fibonacci.py ├── Fibonacci └── Fibonacci.py ├── Fidgetspinner.py ├── FindHash.py ├── First └── First.cpp ├── GUI Calculator └── GUI_Calculator.py ├── Guess The number.py ├── Heap sort.py ├── Heap_Sort └── Heap_sort.py ├── ImageToAscii ├── README.md ├── imgtoascii.py └── py.jpg ├── Insertion sort.C ├── Insertion sort.py ├── Jugglingalgorithm └── Jugglingalgorithm.py ├── Krishnangshu Paul └── Krishnangshu Paul ├── LICENSE ├── LIS └── Longest_Increasing_Subsequence.py ├── Magic Grid └── Magic Grid.py ├── MaxPeaks └── MaxPeaks.cpp ├── Merge Sort └── Merge_Sort.py ├── Merge sort.py ├── Monty-Hall-Python-Simulation.py ├── N_queen └── n_queen.py ├── Naive Bayes Classifier Os └── Naive Bayes classifier .ipynb ├── PainterPartitionProblem.java ├── PalindromeString.py ├── Password_genertaor.py ├── Pattern(1) └── Pattern.9cpp ├── Pattern └── Pattern ├── Pattern21.py ├── Pong Game └── pong.py ├── Pyramid └── Pyramid.py ├── Python content based recommendation system ├── Content_recommendation.ipynb └── quadratic.py ├── Python ├── Alarm clock.py ├── Music Player.py ├── Music player.py ├── Python.py ├── QR-Code-Generator.py ├── clickeventdrivenprogram.py └── factorial.py ├── QR Code Generator └── QR Code Generator.py ├── Radix_Sorting └── Radix_sorting.py ├── Ram Kaminwar └── ram.py ├── RecursiveFactorial.py ├── Reverse.py ├── Richard Nikolas └── checkPrimeOnInterval.py ├── Rock, Paper and Scissors Game with Python.py ├── RockPaperScissor └── RockPaperScissor.py ├── Rolling Dice Simulator.py ├── Rot13 └── rot13.py ├── Runner -.lnk ├── Runner Game ├── .idea │ ├── .gitignore │ ├── Pygame building blocks.iml │ ├── inspectionProfiles │ │ └── profiles_settings.xml │ ├── misc.xml │ └── modules.xml ├── Runner - Copy.py ├── Runner - Shortcut.lnk ├── Runner.py ├── audio │ ├── jump.mp3 │ └── music.wav ├── font │ └── Pixeltype.ttf └── graphics │ ├── Fly │ ├── Fly1.png │ └── Fly2.png │ ├── Player │ ├── Layer 10.png │ ├── Layer 11.png │ ├── Layer 12.png │ ├── Layer 2.png │ ├── Layer 3.png │ ├── Layer 4.png │ ├── Layer 5.png │ ├── Layer 6.png │ ├── Layer 7.png │ ├── Layer 8.png │ ├── Layer 9.png │ ├── jump.png │ ├── layer 1.png │ ├── player_stand.png │ ├── player_walk_1.png │ ├── player_walk_2.png │ └── stickmanrun.zip │ ├── Sky.png │ ├── city.png │ ├── endlessparallax_01_bybcsilva.png │ ├── endlessparallax_02_bybcsilva.png │ ├── endlessparallax_03_bybcsilva.png │ ├── endlessparallax_04_bybcsilva.png │ ├── ground.png │ ├── new-btn-bg-635611.png │ ├── snail │ ├── snail1.png │ └── snail2.png │ └── spritesheet.png ├── Script - Convert to Gray Image ├── grayImg.py ├── requirements.txt └── test.jpg ├── Script - Random Song Player ├── randomSongPlayer.py └── requirements.txt ├── Shivam Garg └── fibonacci.py ├── Shivam Mishra ├── NthStair.py ├── subsequence_of_Array.py └── validateSubsequence.py ├── Siddhesh.py ├── SieveOfEratosthenes.py ├── Sieve_of_Eratosthenes.py ├── Speaking News App └── Speaking News App.py ├── Spiral.py ├── StringPermutation.py ├── Sudoku.py ├── Tetris.py ├── Text to speech └── Text to speech.py ├── Text_to_speech_convertor └── Text_to_speech_convertor.py ├── Tic Tac Toe Game └── tic_tac_toe.py ├── Tic_tac_toe.py ├── Timer └── Timer.py ├── To_check_prime_number.py ├── Travelling Salesman Problem ├── tsp_ni.py └── tsp_nn.py ├── Tushar Nain └── BinarySearch.py ├── Varad Chandrawar ├── Additionoftwomatrix.py └── LCM.py ├── Varun Kotgire └── Prime.py ├── Web_Scrapping.py ├── Youtube_video_downloader └── Youtube_video_downloader.py ├── alarm_clock.py ├── athul ├── .largest.py └── largest.py ├── attendance.txt ├── auto_clicker using automation ├── auto_clicker.py └── readme.md ├── binary_search.py ├── bubble_sort.py ├── bubblesort └── bubblesort.py ├── caesar_cipher.py ├── calculator.py ├── calculator ├── .ipynb_checkpoints │ └── calculator-checkpoint.ipynb ├── calc.ui └── calculator.ipynb ├── chat_bot ├── Readme.md └── chat_bot.py ├── check_palindrome_symmetric.py ├── clock └── clock.py ├── comment.py ├── count no. of One bits ├── dav └── program.py ├── detect └── detect.py ├── divyansh99 └── divyansh99.cpp ├── extract_keyword.py ├── factorial.py ├── factorial └── factorial.py ├── fibonacciSeries └── fibonacciSeries.py ├── flappy ├── gallery │ ├── audio │ │ ├── die.wav │ │ ├── hit.wav │ │ ├── point.wav │ │ ├── swoosh.wav │ │ └── wing.wav │ └── sprites │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ ├── 9.png │ │ ├── background.png │ │ ├── base.png │ │ ├── bird.png │ │ ├── message.png │ │ └── pipe.png └── main.py ├── flask_tutorial.zip ├── floor and ceil bst.py ├── game.py ├── garvit └── garvit.py ├── gaurav shah ├── get Current Time └── get Current Time.py ├── get_date.py ├── greater_num.py ├── guess_num.py ├── hacktober translator └── hacktober translator.py ├── hacktoberfest-quiz └── hacktoberfest-quiz.py ├── hacktoberfest2022 ├── hacktoberfest__2022 ├── hailstone_Sequence.py ├── handwritten number detection.ipynb ├── heart └── heart.py ├── helloworld.py ├── insertion_sort └── insertion_sort.py ├── instagram downloader ├── README.md ├── igdown.py └── requirements.txt ├── lcs └── lcs.py ├── linear regression └── Linear_Regression_Python.ipynb ├── linearsearch_asad.py ├── linkedList └── linkedList.py ├── linkedlist.py ├── logistic_regression └── logistic_regression.py ├── matrix.py ├── music player ├── news narrator.py ├── node └── node.py ├── num_again └── num_again.py ├── number_guessing_game.py ├── palindrome.py ├── password_generator.py ├── pattern.py ├── pattern19 └── pattern19.py ├── patternpyramid.py ├── pearson_correlation.py ├── pencil_sketch.py ├── perfect_no_in_range.py ├── perfectnumber.py ├── phone_number.py ├── plaindrome └── plaindrome.py ├── pong_1 └── pong_1.py ├── prime.py ├── prime └── prime.py ├── pyautogui-SpiralDrawer ├── README.md ├── pyautogui.py └── square_spiral.png ├── pyramid,c++.txt ├── python.py ├── python111 └── python111.py ├── quicksort └── quicksort.py ├── quiz.py ├── quiz_animal.py ├── radixsort.py ├── random_pass └── random_pass.py ├── recursive_factorial └── recursive_factorial.py ├── separate audio └── separate audio.py ├── set2.py ├── set5.py ├── shellsort.py ├── shruti.py ├── slidingwindow.py ├── snake game └── snake game.py ├── speech to text.py ├── split_and_join_string └── split_and_join_string.py ├── stringtodatetime.py ├── supportvectormachine └── supportvectormachine.py ├── text.py ├── time_calculator(1) └── time_calculator (1).py ├── tower_of_Hanoi └── tower_of_Hanoi.py ├── twitter scrape └── scrape.py ├── vowel.py └── warshall └── warshall.py /About_Python: -------------------------------------------------------------------------------- 1 | PYTHON- 2 | 3 | Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. 4 | It is used for: 5 | 1.Web development (server-side) 6 | 2.Software development 7 | 3.Mathematics 8 | 4.System scripting 9 | 10 | What can Python do? 11 | 1.Python can be used on a server to create web applications. 12 | 2.Python can be used alongside software to create workflows. 13 | 3.Python can connect to database systems. It can also read and modify files. 14 | 4.Python can be used to handle big data and perform complex mathematics. 15 | 5.Python can be used for rapid prototyping, or for production-ready software development. 16 | 17 | Why Python? 18 | 1.Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). 19 | 2.Python has a simple syntax similar to the English language. 20 | 3.Python has syntax that allows developers to write programs with fewer lines than some other programming languages. 21 | 4.Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick. 22 | 5.Python can be treated in a procedural way, an object-oriented way or a functional way. 23 | 24 | It is possible to write Python in an Integrated Development Environment, such as Thonny, Pycharm, Netbeans or Eclipse which are particularly useful when managing larger 25 | collections of Python files. 26 | *Python Syntax compared to other programming languages 27 | *Python was designed for readability, and has some similarities to the English language with influence from mathematics. 28 | *Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses. 29 | *Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose. 30 | -------------------------------------------------------------------------------- /Alarm/alarm.py: -------------------------------------------------------------------------------- 1 | """ Alarm Clock 2 | ---------------------------------------- 3 | """ 4 | import datetime 5 | import os 6 | import time 7 | import random 8 | import webbrowser 9 | 10 | # If video URL file does not exist, create one 11 | if not os.path.isfile("youtube_alarm_videos.txt"): 12 | print('Creating "youtube_alarm_videos.txt"...') 13 | with open("youtube_alarm_videos.txt", "w") as alarm_file: 14 | alarm_file.write("https:#www.youtube.com/watch?v=anM6uIZvx74") 15 | 16 | 17 | def check_alarm_input(alarm_time): 18 | """Checks to see if the user has entered in a valid alarm time""" 19 | if len(alarm_time) == 1: # [Hour] Format 20 | if alarm_time[0] < 24 and alarm_time[0] >= 0: 21 | return True 22 | if len(alarm_time) == 2: # [Hour:Minute] Format 23 | if ( 24 | alarm_time[0] < 24 25 | and alarm_time[0] >= 0 26 | and alarm_time[1] < 60 27 | and alarm_time[1] >= 0 28 | ): 29 | return True 30 | elif len(alarm_time) == 3: # [Hour:Minute:Second] Format 31 | if ( 32 | alarm_time[0] < 24 33 | and alarm_time[0] >= 0 34 | and alarm_time[1] < 60 35 | and alarm_time[1] >= 0 36 | and alarm_time[2] < 60 37 | and alarm_time[2] >= 0 38 | ): 39 | return True 40 | return False 41 | 42 | 43 | # Get user input for the alarm time 44 | print("Set a time for the alarm (Ex. 06:30 or 18:30:00)") 45 | while True: 46 | alarm_input = input(">> ") 47 | try: 48 | alarm_time = [int(n) for n in alarm_input.split(":")] 49 | if check_alarm_input(alarm_time): 50 | break 51 | else: 52 | raise ValueError 53 | except ValueError: 54 | print("ERROR: Enter time in HH:MM or HH:MM:SS format") 55 | # Convert the alarm time from [H:M] or [H:M:S] to seconds 56 | seconds_hms = [3600, 60, 1] # Number of seconds in an Hour, Minute, and Second 57 | alarm_seconds = sum([a * b for a, b in zip(seconds_hms[: len(alarm_time)], alarm_time)]) 58 | # Get the current time of day in seconds 59 | now = datetime.datetime.now() 60 | current_time_seconds = sum( 61 | [a * b for a, b in zip(seconds_hms, [now.hour, now.minute, now.second])] 62 | ) 63 | # Calculate the number of seconds until alarm goes off 64 | time_diff_seconds = alarm_seconds - current_time_seconds 65 | # If time difference is negative, set alarm for next day 66 | if time_diff_seconds < 0: 67 | time_diff_seconds += 86400 # number of seconds in a day 68 | # Display the amount of time until the alarm goes off 69 | print("Alarm set to go off in %s" % datetime.timedelta(seconds=time_diff_seconds)) 70 | # Sleep until the alarm goes off 71 | time.sleep(time_diff_seconds) 72 | # Time for the alarm to go off 73 | print("Wake Up!") 74 | # Load list of possible video URLs 75 | with open("youtube_alarm_videos.txt", "r") as alarm_file: 76 | videos = alarm_file.readlines() 77 | # Open a random video from the list 78 | webbrowser.open(random.choice(videos)) 79 | -------------------------------------------------------------------------------- /ArmstrongNum.py: -------------------------------------------------------------------------------- 1 | # Python program to determine whether 2 | # the number is Armstrong number or not 3 | 4 | def power(x, y): 5 | 6 | if y == 0: 7 | return 1 8 | if y % 2 == 0: 9 | return power(x, y // 2) * power(x, y // 2) 10 | 11 | return x * power(x, y // 2) * power(x, y // 2) 12 | 13 | 14 | def order(x): 15 | 16 | n = 0 17 | while (x != 0): 18 | n = n + 1 19 | x = x // 10 20 | 21 | return n 22 | 23 | def isArmstrong(x): 24 | 25 | n = order(x) 26 | temp = x 27 | sum1 = 0 28 | 29 | while (temp != 0): 30 | r = temp % 10 31 | sum1 = sum1 + power(r, n) 32 | temp = temp // 10 33 | 34 | return (sum1 == x) 35 | 36 | 37 | x = 153 38 | print(isArmstrong(x)) 39 | 40 | x = 1246 41 | print(isArmstrong(x)) 42 | -------------------------------------------------------------------------------- /ArmstrongNum/ArmstrongNum.py: -------------------------------------------------------------------------------- 1 | # Python program to determine whether 2 | # the number is Armstrong number or not 3 | 4 | def power(x, y): 5 | 6 | if y == 0: 7 | return 1 8 | if y % 2 == 0: 9 | return power(x, y // 2) * power(x, y // 2) 10 | 11 | return x * power(x, y // 2) * power(x, y // 2) 12 | 13 | 14 | def order(x): 15 | 16 | n = 0 17 | while (x != 0): 18 | n = n + 1 19 | x = x // 10 20 | 21 | return n 22 | 23 | def isArmstrong(x): 24 | 25 | n = order(x) 26 | temp = x 27 | sum1 = 0 28 | 29 | while (temp != 0): 30 | r = temp % 10 31 | sum1 = sum1 + power(r, n) 32 | temp = temp // 10 33 | 34 | return (sum1 == x) 35 | 36 | 37 | x = 153 38 | print(isArmstrong(x)) 39 | 40 | x = 1246 41 | print(isArmstrong(x)) 42 | -------------------------------------------------------------------------------- /BFS tree traversal algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | struct Node { 5 | int data; 6 | struct Node *left, *right; 7 | }; 8 | Node* newNode(int data) { 9 | Node *temp = new Node; 10 | temp->data = data; 11 | temp->left = temp->right = NULL; 12 | return temp; 13 | } 14 | int main() { 15 | Node *root = newNode(1); 16 | root->left = newNode(2); 17 | root->right = newNode(3); 18 | root->left->left = newNode(4); 19 | root->left->right = newNode(5); 20 | cout << "Level Order traversal of binary tree is 21 | "; 22 | queue q; 23 | q.push(root); 24 | while (q.empty() == false) { 25 | Node *node = q.front(); 26 | cout << node->data << " "; 27 | q.pop(); 28 | if (node->left != NULL) 29 | q.push(node->left); 30 | if (node->right != NULL) 31 | q.push(node->right); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Binary Search in C++.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // A recursive binary search function. It returns 5 | // location of x in given array arr[l..r] is present, 6 | // otherwise -1 7 | int binarySearch(int arr[], int l, int r, int x) 8 | { 9 | if (r >= l) { 10 | int mid = l + (r - l) / 2; 11 | 12 | // If the element is present at the middle 13 | // itself 14 | if (arr[mid] == x) 15 | return mid; 16 | 17 | // If element is smaller than mid, then 18 | // it can only be present in left subarray 19 | if (arr[mid] > x) 20 | return binarySearch(arr, l, mid - 1, x); 21 | 22 | // Else the element can only be present 23 | // in right subarray 24 | return binarySearch(arr, mid + 1, r, x); 25 | } 26 | 27 | // We reach here when element is not 28 | // present in array 29 | return -1; 30 | } 31 | 32 | int main(void) 33 | { 34 | int arr[] = { 2, 3, 4, 10, 40 }; 35 | int x = 10; 36 | int n = sizeof(arr) / sizeof(arr[0]); 37 | int result = binarySearch(arr, 0, n - 1, x); 38 | (result == -1) 39 | ? cout << "Element is not present in array" 40 | : cout << "Element is present at index " << result; 41 | return 0; 42 | } -------------------------------------------------------------------------------- /BinaryToDecimal and DecimalToBinary/BinaryToDecimal: -------------------------------------------------------------------------------- 1 | def binaryToDecimal(n): 2 | 3 | ans, i = 0, 0 4 | while(n != 0): 5 | digit = n % 10 6 | ans = ans + digit * pow(2, i) 7 | n = n//10 8 | i += 1 9 | print(ans) 10 | 11 | 12 | # Driver code 13 | if __name__ == '__main__': 14 | val = int(input("Enter a binary number: ")) 15 | binaryToDecimal(val) 16 | 17 | -------------------------------------------------------------------------------- /BinaryToDecimal and DecimalToBinary/DecimalToBinary: -------------------------------------------------------------------------------- 1 | def DecimalToBinary(n): 2 | 3 | ans, i = 0, 0 4 | while(n != 0): 5 | bit = n&1 6 | ans = ans + bit * pow(10, i) 7 | n = n>>1 8 | i += 1 9 | print(ans) 10 | 11 | 12 | # Driver code 13 | if __name__ == '__main__': 14 | val = int(input("Enter a decimal number: ")) 15 | DecimalToBinary(val) 16 | -------------------------------------------------------------------------------- /Binary_Search/binarySearch.py: -------------------------------------------------------------------------------- 1 | # Python 3 program for recursive binary search. 2 | 3 | 4 | 5 | def binary_search(arr, low, high, x): 6 | 7 | if high >= low: 8 | 9 | mid = (high + low) // 2 10 | 11 | 12 | if arr[mid] == x: 13 | return mid 14 | 15 | 16 | elif arr[mid] > x: 17 | return binary_search(arr, low, mid - 1, x) 18 | 19 | 20 | else: 21 | return binary_search(arr, mid + 1, high, x) 22 | 23 | else: 24 | 25 | return -1 26 | 27 | # Test array 28 | arr = [ 2, 3, 4, 10, 40 ] 29 | x = 10 30 | 31 | 32 | result = binary_search(arr, 0, len(arr)-1, x) 33 | 34 | if result != -1: 35 | print("Element is present at index", str(result)) 36 | else: 37 | print("Element is not present in array") 38 | -------------------------------------------------------------------------------- /Breadth_First_Search.py: -------------------------------------------------------------------------------- 1 | '''graph algorithm which is used to traverse a graph to find a particular node to ensure that we have visited all the nodes by crossing a layer at each step. 2 | In the process, it first visits all the neighbouring vertices of s, then it visits the vertices that have a distance of two of s, then a distance of three and so on.''' 3 | class Queue(): 4 | def __init__(self): 5 | self.size = 0 6 | self.list = [] 7 | 8 | def enqueue(self, data): 9 | self.list.append(data) 10 | self.size += 1 11 | 12 | def dequeue(self): 13 | try: 14 | self.size -= 1 15 | return self.list.pop(0) 16 | except Exception as error: 17 | print(f'{error} is not possible') 18 | 19 | def xprint(self, index): 20 | print(self.list[index]) 21 | def breadth_first(graph, root): 22 | queue = Queue() 23 | visited_nodes = list() 24 | queue.enqueue(root) 25 | visited_nodes.append(root) 26 | current_node = root 27 | 28 | while queue.size > 0: 29 | current_node = queue.dequeue() 30 | adj_nodes = graph[current_node] 31 | remaining_elements = sorted(set(adj_nodes) - set(visited_nodes)) 32 | 33 | if len(remaining_elements) > 0: 34 | for element in remaining_elements: 35 | visited_nodes.append(element) 36 | queue.enqueue(element) 37 | 38 | return visited_nodes 39 | if __name__ == '__main__': 40 | 41 | graph = dict() 42 | 43 | graph['A'] = ['B', 'G', 'D'] 44 | graph['B'] = ['A', 'F', 'E'] 45 | graph['C'] = ['F', 'H'] 46 | graph['D'] = ['F', 'A'] 47 | graph['E'] = ['B', 'G'] 48 | graph['F'] = ['B', 'D', 'C'] 49 | graph['G'] = ['A', 'E'] 50 | graph['H'] = ['C'] 51 | 52 | print(breadth_first(graph, 'A')) 53 | -------------------------------------------------------------------------------- /Bubble Sort.C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | void swap(int* xp, int* yp) 10 | 11 | { 12 | 13 | int temp = *xp; 14 | 15 | *xp = *yp; 16 | 17 | *yp = temp; 18 | 19 | } 20 | 21 | 22 | 23 | 24 | 25 | void bubbleSort(int arr[], int n) 26 | 27 | { 28 | 29 | int i, j; 30 | 31 | for (i = 0; i < n - 1; i++) 32 | 33 | 34 | 35 | 36 | 37 | for (j = 0; j < n - i - 1; j++) 38 | 39 | if (arr[j] > arr[j + 1]) 40 | 41 | swap(&arr[j], &arr[j + 1]); 42 | 43 | } 44 | 45 | 46 | 47 | 48 | 49 | void printArray(int arr[], int size) 50 | 51 | { 52 | 53 | int i; 54 | 55 | for (i = 0; i < size; i++) 56 | 57 | printf("%d ", arr[i]); 58 | 59 | printf("\n"); 60 | 61 | } 62 | 63 | 64 | 65 | 66 | 67 | int main() 68 | 69 | { 70 | 71 | int arr[] = { 64, 34, 25, 12, 22, 11, 90 }; 72 | 73 | int n = sizeof(arr) / sizeof(arr[0]); 74 | 75 | bubbleSort(arr, n); 76 | 77 | printf("Sorted array: \n"); 78 | 79 | printArray(arr, n); 80 | 81 | return 0; 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Bubble sort.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | def bubbleSort(arr): 6 | 7 | n = len(arr) 8 | 9 | 10 | 11 | swapped = False 12 | 13 | 14 | 15 | for i in range(n-1): 16 | 17 | 18 | 19 | for j in range(0, n-i-1): 20 | 21 | 22 | 23 | 24 | if arr[j] > arr[j + 1]: 25 | 26 | swapped = True 27 | 28 | arr[j], arr[j + 1] = arr[j + 1], arr[j] 29 | 30 | 31 | 32 | if not swapped: 33 | 34 | 35 | 36 | return 37 | 38 | 39 | 40 | 41 | arr = [64, 34, 25, 12, 22, 11, 90] 42 | 43 | bubbleSort(arr) 44 | 45 | 46 | print("Sorted array is:") 47 | 48 | for i in range(len(arr)): 49 | 50 | print("% d" % arr[i], end=" ") 51 | -------------------------------------------------------------------------------- /Bucket_Sort/bucket_sort.py: -------------------------------------------------------------------------------- 1 | # Bucket Sort in Python 2 | 3 | 4 | def bucketSort(array): 5 | bucket = [] 6 | 7 | # Create empty buckets 8 | for i in range(len(array)): 9 | bucket.append([]) 10 | 11 | # Insert elements into their respective buckets 12 | for j in array: 13 | index_b = int(10 * j) 14 | bucket[index_b].append(j) 15 | 16 | # Sort the elements of each bucket 17 | for i in range(len(array)): 18 | bucket[i] = sorted(bucket[i]) 19 | 20 | # Get the sorted elements 21 | k = 0 22 | for i in range(len(array)): 23 | for j in range(len(bucket[i])): 24 | array[k] = bucket[i][j] 25 | k += 1 26 | return array 27 | 28 | 29 | array = [.42, .32, .33, .52, .37, .47, .51] 30 | print("Sorted Array in descending order is") 31 | print(bucketSort(array)) -------------------------------------------------------------------------------- /Calc.py: -------------------------------------------------------------------------------- 1 | # Program make a simple calculator 2 | 3 | # This function adds two numbers 4 | 5 | def add(x, y): 6 | 7 | return x + y 8 | 9 | # This function subtracts two numbers 10 | 11 | def subtract(x, y): 12 | 13 | return x - y 14 | 15 | # This function multiplies two numbers 16 | 17 | def multiply(x, y): 18 | 19 | return x * y 20 | 21 | # This function divides two numbers 22 | 23 | def divide(x, y): 24 | 25 | return x / y 26 | 27 | print("Select operation.") 28 | 29 | print("1.Add") 30 | 31 | print("2.Subtract") 32 | 33 | print("3.Multiply") 34 | 35 | print("4.Divide") 36 | 37 | while True: 38 | 39 | # take input from the user 40 | 41 | choice = input("Enter choice(1/2/3/4): ") 42 | 43 | # check if choice is one of the four options 44 | 45 | if choice in ('1', '2', '3', '4'): 46 | 47 | num1 = float(input("Enter first number: ")) 48 | 49 | num2 = float(input("Enter second number: ")) 50 | 51 | if choice == '1': 52 | 53 | print(num1, "+", num2, "=", add(num1, num2)) 54 | 55 | elif choice == '2': 56 | 57 | print(num1, "-", num2, "=", subtract(num1, num2)) 58 | 59 | elif choice == '3': 60 | 61 | print(num1, "*", num2, "=", multiply(num1, num2)) 62 | 63 | elif choice == '4': 64 | 65 | print(num1, "/", num2, "=", divide(num1, num2)) 66 | 67 | 68 | 69 | # check if user wants another calculation 70 | 71 | # break the while loop if answer is no 72 | 73 | next_calculation = input("Let's do next calculation? (yes/no): ") 74 | 75 | if next_calculation == "no": 76 | 77 | break 78 | 79 | 80 | 81 | else: 82 | 83 | print("Invalid Input") 84 | -------------------------------------------------------------------------------- /Calculator.py: -------------------------------------------------------------------------------- 1 | # pip install tkinter 2 | import tkinter as tk 3 | import tkinter.messagebox 4 | from tkinter.constants import SUNKEN 5 | 6 | window = tk.Tk() 7 | window.title('Calculator-GeeksForGeeks') 8 | frame = tk.Frame(master=window, bg="skyblue", padx=10) 9 | frame.pack() 10 | entry = tk.Entry(master=frame, relief=SUNKEN, borderwidth=3, width=30) 11 | entry.grid(row=0, column=0, columnspan=3, ipady=2, pady=2) 12 | 13 | 14 | def myclick(number): 15 | entry.insert(tk.END, number) 16 | 17 | 18 | def equal(): 19 | try: 20 | y = str(eval(entry.get())) 21 | entry.delete(0, tk.END) 22 | entry.insert(0, y) 23 | except: 24 | tkinter.messagebox.showinfo("Error", "Syntax Error") 25 | 26 | 27 | def clear(): 28 | entry.delete(0, tk.END) 29 | 30 | 31 | button_1 = tk.Button(master=frame, text='1', padx=15, 32 | pady=5, width=3, command=lambda: myclick(1)) 33 | button_1.grid(row=1, column=0, pady=2) 34 | button_2 = tk.Button(master=frame, text='2', padx=15, 35 | pady=5, width=3, command=lambda: myclick(2)) 36 | button_2.grid(row=1, column=1, pady=2) 37 | button_3 = tk.Button(master=frame, text='3', padx=15, 38 | pady=5, width=3, command=lambda: myclick(3)) 39 | button_3.grid(row=1, column=2, pady=2) 40 | button_4 = tk.Button(master=frame, text='4', padx=15, 41 | pady=5, width=3, command=lambda: myclick(4)) 42 | button_4.grid(row=2, column=0, pady=2) 43 | button_5 = tk.Button(master=frame, text='5', padx=15, 44 | pady=5, width=3, command=lambda: myclick(5)) 45 | button_5.grid(row=2, column=1, pady=2) 46 | button_6 = tk.Button(master=frame, text='6', padx=15, 47 | pady=5, width=3, command=lambda: myclick(6)) 48 | button_6.grid(row=2, column=2, pady=2) 49 | button_7 = tk.Button(master=frame, text='7', padx=15, 50 | pady=5, width=3, command=lambda: myclick(7)) 51 | button_7.grid(row=3, column=0, pady=2) 52 | button_8 = tk.Button(master=frame, text='8', padx=15, 53 | pady=5, width=3, command=lambda: myclick(8)) 54 | button_8.grid(row=3, column=1, pady=2) 55 | button_9 = tk.Button(master=frame, text='9', padx=15, 56 | pady=5, width=3, command=lambda: myclick(9)) 57 | button_9.grid(row=3, column=2, pady=2) 58 | button_0 = tk.Button(master=frame, text='0', padx=15, 59 | pady=5, width=3, command=lambda: myclick(0)) 60 | button_0.grid(row=4, column=1, pady=2) 61 | 62 | button_add = tk.Button(master=frame, text="+", padx=15, 63 | pady=5, width=3, command=lambda: myclick('+')) 64 | button_add.grid(row=5, column=0, pady=2) 65 | 66 | button_subtract = tk.Button( 67 | master=frame, text="-", padx=15, pady=5, width=3, command=lambda: myclick('-')) 68 | button_subtract.grid(row=5, column=1, pady=2) 69 | 70 | button_multiply = tk.Button( 71 | master=frame, text="*", padx=15, pady=5, width=3, command=lambda: myclick('*')) 72 | button_multiply.grid(row=5, column=2, pady=2) 73 | 74 | button_div = tk.Button(master=frame, text="/", padx=15, 75 | pady=5, width=3, command=lambda: myclick('/')) 76 | button_div.grid(row=6, column=0, pady=2) 77 | 78 | button_clear = tk.Button(master=frame, text="clear", 79 | padx=15, pady=5, width=12, command=clear) 80 | button_clear.grid(row=6, column=1, columnspan=2, pady=2) 81 | 82 | button_equal = tk.Button(master=frame, text="=", padx=15, 83 | pady=5, width=9, command=equal) 84 | button_equal.grid(row=7, column=0, columnspan=3, pady=2) 85 | 86 | window.mainloop() 87 | -------------------------------------------------------------------------------- /Categorize Password/Categorize Password.py: -------------------------------------------------------------------------------- 1 | # Categorizing password as Strong or 2 | # Weak in Python using Regex 3 | 4 | 5 | import re 6 | 7 | 8 | # Function to categorize password 9 | def password(v): 10 | 11 | # the password should not be a 12 | # newline or space 13 | if v == "\n" or v == " ": 14 | return "Password cannot be a newline or space!" 15 | 16 | # the password length should be in 17 | # between 9 and 20 18 | if 9 <= len(v) <= 20: 19 | 20 | # checks for occurrence of a character 21 | # three or more times in a row 22 | if re.search(r'(.)\1\1', v): 23 | return "Weak Password: Same character repeats three or more times in a row" 24 | 25 | # checks for occurrence of same string 26 | # pattern( minimum of two character length) 27 | # repeating 28 | if re.search(r'(..)(.*?)\1', v): 29 | return "Weak password: Same string pattern repetition" 30 | 31 | else: 32 | return "Strong Password!" 33 | 34 | else: 35 | return "Password length must be 9-20 characters!" 36 | 37 | # Main method 38 | def main(): 39 | 40 | # Driver code 41 | print(password("Qggf!@ghf3")) 42 | print(password("Gggksforgeeks")) 43 | print(password("aaabnil1gu")) 44 | print(password("Aasd!feasn")) 45 | print(password("772*hd897")) 46 | print(password(" ")) 47 | 48 | 49 | # Driver Code 50 | if __name__ == '__main__': 51 | main() 52 | -------------------------------------------------------------------------------- /Contributor.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Contributing Guidelines 📜 4 |
5 | 6 | 7 | *** 8 |

If you are new to open-source and would like to make your first contribution, please participate in this project.

9 |

Follow the steps below :-

10 | 11 | ## Git Setup Guide 12 | *** 13 | ### To initialise Git, write 14 | ```bash 15 | git init 16 | ``` 17 | 18 | ### 1. Configure your local Git 19 | --- 20 | ```bash 21 | git config --global user.name "github username" 22 | ``` 23 | 24 | ```bash 25 | git config --global user.email "email address" 26 | ``` 27 | 28 | ### 2. Go to the first-contribution repository and Fork it. 29 | --- 30 | * The term fork refers to a rough copy of a repository. When you fork a repository, you are able to test and debug changes without affecting the original project. In addition to proposing changes to resolve bugs, forking is also used excessively for this purpose. 31 | 32 | * Click on Code Button and copy the URL of your forked Repository 33 | 34 | ### 3. Switch to your Git bash window, and enter the following : 35 | --- 36 | * Clone the Forked project on your local system 37 | 38 | ```bash 39 | git clone https://github.com/eduardconstantin/Comic-book-button-anim.git 40 | ``` 41 | 42 | 43 | 44 | **Note: Do not fill this detail twice or more than that.** 45 | 46 | 47 | ### 4. Creating a Pull request 48 | --- 49 | #### Create a branch 50 | 51 | * A branch is designed to encapsulate a group of changes. These changes might be thrown away, entirely rewritten or in the majority of cases they’ll be promoted into the main history of the codebase - via a merge. 52 | 53 | 54 | * For creating a branch 55 | 56 | ```bash 57 | git branch branch_name 58 | ``` 59 | 60 | * Checkout to the created branch 61 | 62 | ```bash 63 | git checkout branch_name 64 | ``` 65 | 66 | 67 | * Now add the files using the git command 68 | 69 | ```bash 70 | git add . 71 | ``` 72 | * Commit the changes to the local project 73 | 74 | ```bash 75 | git commit -m "Added my data" 76 | ``` 77 | 78 | * Push the changes to your forked github repo 79 | ```bash 80 | git push origin branch_name 81 | ``` 82 | 83 | ### 5. Final Steps 84 | --- 85 | * Open your forked git repository, you will get a message like as shown in the figure (if not then refresh the page). 86 | 87 | **Click on "Contribute 👆🏻** 88 | 89 | 90 | * Now click on "Open pull request" 91 | 92 | * Click on "Create pull request" 93 | 94 | * You may add a Comment to your Pull Request 95 | -------------------------------------------------------------------------------- /CountdownTimer.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def countdown(time_sec): 4 | while time_sec: 5 | mins, secs = divmod(time_sec, 60) 6 | timeformat = '{:02d}:{:02d}'.format(mins, secs) 7 | print(timeformat, end='\r') 8 | time.sleep(1) 9 | time_sec -= 1 10 | 11 | print("stop") 12 | 13 | countdown(5) 14 | -------------------------------------------------------------------------------- /Dictionary.py: -------------------------------------------------------------------------------- 1 | # Creating an empty Dictionary 2 | 3 | Dict = {} 4 | 5 | print("Empty Dictionary: ") 6 | 7 | print(Dict) 8 | 9 | 10 | 11 | # Creating a Dictionary 12 | 13 | # with dict() method 14 | 15 | Dict = dict({1: 'Geeks', 2: 'For', 3: 'Geeks'}) 16 | 17 | print("\nDictionary with the use of dict(): ") 18 | 19 | print(Dict) 20 | 21 | 22 | 23 | # Creating a Dictionary 24 | 25 | # with each item as a Pair 26 | 27 | Dict = dict([(1, 'Geeks'), (2, 'For')]) 28 | 29 | print("\nDictionary with each item as a pair: ") 30 | 31 | print(Dict) 32 | -------------------------------------------------------------------------------- /Digital clock.py: -------------------------------------------------------------------------------- 1 | from tkinter import Label, Tk 2 | import time 3 | app_window = Tk() 4 | app_window.title("Digital Clock") 5 | app_window.geometry("420x150") 6 | app_window.resizable(1,1) 7 | 8 | text_font= ("Boulder", 68, 'bold') 9 | background = "#f2e750" 10 | foreground= "#363529" 11 | border_width = 25 12 | 13 | label = Label(app_window, font=text_font, bg=background, fg=foreground, bd=border_width) 14 | label.grid(row=0, column=1) 15 | 16 | def digital_clock(): 17 | time_live = time.strftime("%H:%M:%S") 18 | label.config(text=time_live) 19 | label.after(200, digital_clock) 20 | 21 | digital_clock() 22 | app_window.mainloop() 23 | -------------------------------------------------------------------------------- /Factorial.py: -------------------------------------------------------------------------------- 1 | # Python program to find the factorial of a number provided by the user 2 | # using recursion 3 | 4 | def factorial(x): 5 | """This is a recursive function 6 | to find the factorial of an integer""" 7 | 8 | if x == 1: 9 | return 1 10 | else: 11 | # recursive call to the function 12 | return (x * factorial(x-1)) 13 | 14 | 15 | # change the value for a different result 16 | #num = 7 17 | 18 | # to take input from the user 19 | num = int(input("Enter a number: ")) 20 | 21 | # call the factorial function 22 | result = factorial(num) 23 | print("The factorial of", num, "is", result) -------------------------------------------------------------------------------- /Fibonacci.py: -------------------------------------------------------------------------------- 1 | # Program to display the Fibonacci sequence up to n-th term 2 | 3 | nterms = int(input("How many terms? ")) 4 | 5 | # first two terms 6 | n1, n2 = 0, 1 7 | count = 0 8 | 9 | # check if the number of terms is valid 10 | if nterms <= 0: 11 | print("Please enter a positive integer") 12 | # if there is only one term, return n1 13 | elif nterms == 1: 14 | print("Fibonacci sequence upto",nterms,":") 15 | print(n1) 16 | # generate fibonacci sequence 17 | else: 18 | print("Fibonacci sequence:") 19 | while count < nterms: 20 | print(n1) 21 | nth = n1 + n2 22 | # update values 23 | n1 = n2 24 | n2 = nth 25 | count += 1 26 | -------------------------------------------------------------------------------- /Fibonacci/Fibonacci.py: -------------------------------------------------------------------------------- 1 | # Program to display the Fibonacci sequence up to n-th term 2 | 3 | nterms = int(input("How many terms? ")) 4 | 5 | # first two terms 6 | n1, n2 = 0, 1 7 | count = 0 8 | 9 | # check if the number of terms is valid 10 | if nterms <= 0: 11 | print("Please enter a positive integer") 12 | # if there is only one term, return n1 13 | elif nterms == 1: 14 | print("Fibonacci sequence upto",nterms,":") 15 | print(n1) 16 | # generate fibonacci sequence 17 | else: 18 | print("Fibonacci sequence:") 19 | while count < nterms: 20 | print(n1) 21 | nth = n1 + n2 22 | # update values 23 | n1 = n2 24 | n2 = nth 25 | count += 1 26 | -------------------------------------------------------------------------------- /Fidgetspinner.py: -------------------------------------------------------------------------------- 1 | 2 | from turtle import * 3 | state = {'turn': 0} 4 | def spinner(): 5 | clear() 6 | angle = state['turn']/10 7 | right(angle) 8 | forward(100) 9 | dot(120, 'red') 10 | back(100) 11 | right(120) 12 | forward(100) 13 | dot(120, 'green') 14 | back(100) 15 | right(120) 16 | forward(100) 17 | dot(120, 'blue') 18 | back(100) 19 | right(120) 20 | update() 21 | def animate(): 22 | if state['turn']>0: 23 | state['turn']-=1 24 | 25 | spinner() 26 | ontimer(animate, 20) 27 | def flick(): 28 | state['turn']+=10 29 | 30 | setup(420, 420, 370, 0) 31 | hideturtle() 32 | tracer(False) 33 | width(20) 34 | onkey(flick, 'space') 35 | listen() 36 | animate() 37 | done() -------------------------------------------------------------------------------- /FindHash.py: -------------------------------------------------------------------------------- 1 | # Python program to find the SHA-1 message digest of a file 2 | 3 | # importing the hashlib module 4 | import hashlib 5 | 6 | def hash_file(filename): 7 | """"This function returns the SHA-1 hash 8 | of the file passed into it""" 9 | 10 | # make a hash object 11 | h = hashlib.sha1() 12 | 13 | # open file for reading in binary mode 14 | with open(filename,'rb') as file: 15 | 16 | # loop till the end of the file 17 | chunk = 0 18 | while chunk != b'': 19 | # read only 1024 bytes at a time 20 | chunk = file.read(1024) 21 | h.update(chunk) 22 | 23 | # return the hex representation of digest 24 | return h.hexdigest() 25 | 26 | message = hash_file("track1.mp3") 27 | print(message) 28 | -------------------------------------------------------------------------------- /First/First.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | using namespace std; 6 | 7 | 8 | 9 | // there are four nodes in example graph (graph is 1-based) 10 | 11 | const int n = 4; 12 | 13 | // give maximum to avoid overflow 14 | 15 | const int MAX = 1000000; 16 | 17 | 18 | 19 | // dist[i][j] represents shortest distance to go from i to j 20 | 21 | // this matrix can be calculated for any given graph using 22 | 23 | // all-pair shortest path algorithms 24 | 25 | int dist[n + 1][n + 1] = { 26 | 27 | { 0, 0, 0, 0, 0 }, { 0, 0, 10, 15, 20 }, 28 | 29 | { 0, 10, 0, 25, 25 }, { 0, 15, 25, 0, 30 }, 30 | 31 | { 0, 20, 25, 30, 0 }, 32 | 33 | }; 34 | 35 | 36 | 37 | // memoization for top down recursion 38 | 39 | int memo[n + 1][1 << (n + 1)]; 40 | 41 | 42 | 43 | int fun(int i, int mask) 44 | 45 | { 46 | 47 | // base case 48 | 49 | // if only ith bit and 1st bit is set in our mask, 50 | 51 | // it implies we have visited all other nodes already 52 | 53 | if (mask == ((1 << i) | 3)) 54 | 55 | return dist[1][i]; 56 | 57 | // memoization 58 | 59 | if (memo[i][mask] != 0) 60 | 61 | return memo[i][mask]; 62 | 63 | 64 | 65 | int res = MAX; // result of this sub-problem 66 | 67 | 68 | 69 | // we have to travel all nodes j in mask and end the 70 | 71 | // path at ith node so for every node j in mask, 72 | 73 | // recursively calculate cost of travelling all nodes in 74 | 75 | // mask except i and then travel back from node j to 76 | 77 | // node i taking the shortest path take the minimum of 78 | 79 | // all possible j nodes 80 | 81 | 82 | 83 | for (int j = 1; j <= n; j++) 84 | 85 | if ((mask & (1 << j)) && j != i && j != 1) 86 | 87 | res = std::min(res, fun(j, mask & (~(1 << i))) 88 | 89 | + dist[j][i]); 90 | 91 | return memo[i][mask] = res; 92 | 93 | } 94 | 95 | // Driver program to test above logic 96 | 97 | int main() 98 | 99 | { 100 | 101 | int ans = MAX; 102 | 103 | for (int i = 1; i <= n; i++) 104 | 105 | // try to go from node 1 visiting all nodes in 106 | 107 | // between to i then return from i taking the 108 | 109 | // shortest route to 1 110 | 111 | ans = std::min(ans, fun(i, (1 << (n + 1)) - 1) 112 | 113 | + dist[i][1]); 114 | 115 | 116 | 117 | printf("The cost of most efficient tour = %d", ans); 118 | 119 | 120 | 121 | return 0; 122 | 123 | } 124 | 125 | 126 | 127 | // This code is contributed by Bushipaka Raja Tharun Kumar 128 | -------------------------------------------------------------------------------- /GUI Calculator/GUI_Calculator.py: -------------------------------------------------------------------------------- 1 | #GUI Calculator 2 | 3 | from tkinter import * 4 | 5 | import tkinter.messagebox as a 6 | 7 | root = Tk() 8 | root.title("Calculator") 9 | root.geometry('300x300') 10 | 11 | def calc(): 12 | 13 | root2 = Tk() 14 | root2.title("Operations") 15 | root2.geometry('500x500') 16 | 17 | #Labels 18 | 19 | cal = Label(root2,text = "CALCULATOR",font=40,fg="white",bg="black",width=100) 20 | 21 | f = Label(root2,text = "First Number") 22 | 23 | s = Label(root2,text = "Second Number") 24 | 25 | f_n = Entry(root2) 26 | 27 | s_n = Entry(root2) 28 | 29 | #Positioning 30 | 31 | cal.pack() 32 | 33 | f.place(x=30,y=120) 34 | 35 | s.place(x=30,y=150) 36 | 37 | f_n.place(x=150,y=120) 38 | 39 | s_n.place(x=150,y=150) 40 | 41 | 42 | def add(): 43 | total_sum = (int(f_n.get())+int(s_n.get())) 44 | a.showinfo("Addition",f"Result = {total_sum}") 45 | root2.destroy() 46 | 47 | 48 | def sub(): 49 | total_sub = (int(f_n.get())-int(s_n.get())) 50 | a.showinfo("Subtraction",f"Result = {total_sub}") 51 | root2.destroy() 52 | 53 | 54 | def mul(): 55 | total_mul = (int(f_n.get())*int(s_n.get())) 56 | a.showinfo("Multiplication",f"Result = {total_mul}") 57 | root2.destroy() 58 | 59 | 60 | def div(): 61 | total_div = (int(f_n.get())/int(s_n.get())) 62 | a.showinfo("Multiplication",f"Result = {total_div}") 63 | root2.destroy() 64 | 65 | 66 | def clear(): 67 | f_n.delete(0,'end') 68 | s_n.delete(0,'end') 69 | 70 | #Buttons 71 | 72 | add_b = Button(root2,text = "ADD",fg='white',bg='black',width=10,command=add).place(x=30,y=360) 73 | 74 | sub_b = Button(root2,text = "Subtract",fg='white',bg='black',width=10,command=sub).place(x=140,y=360) 75 | 76 | mul_b = Button(root2,text = "Multiply",fg='white',bg='black',width=10,command=mul).place(x=250,y=360) 77 | 78 | div_b = Button(root2,text="Divide",fg="white",bg="black",width=10,command=div).place(x=360,y=360) 79 | 80 | clear_b = Button(root2,text = "Clear",fg='white',bg='black',width=10,command=clear).place(x=180,y=460) 81 | 82 | butt1 = Button(text = "Calculate",font=30,fg='white',bg='black',command=calc).place(x=110,y=110) 83 | 84 | root.mainloop() -------------------------------------------------------------------------------- /Guess The number.py: -------------------------------------------------------------------------------- 1 | import random 2 | number = random.randint(1,10) 3 | for i in range(0,3): 4 | user = int(input("guess the number")) 5 | if user == number: 6 | print("Hurray!!") 7 | print(f"you guessed the number right it's {number}") 8 | break 9 | if user != number: 10 | print(f"Your guess is incorrect the number is {number}") 11 | -------------------------------------------------------------------------------- /Heap sort.py: -------------------------------------------------------------------------------- 1 | 2 | def heapify(arr, n, i): 3 | 4 | largest = i # Initialize largest as root 5 | 6 | l = 2 * i + 1 # left = 2*i + 1 7 | 8 | r = 2 * i + 2 # right = 2*i + 2 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | if l < n and arr[i] < arr[l]: 17 | 18 | largest = l 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | if r < n and arr[largest] < arr[r]: 27 | 28 | largest = r 29 | 30 | 31 | 32 | 33 | 34 | if largest != i: 35 | 36 | (arr[i], arr[largest]) = (arr[largest], arr[i]) # swap 37 | 38 | 39 | 40 | 41 | 42 | heapify(arr, n, largest) 43 | 44 | 45 | 46 | 47 | 48 | def heapSort(arr): 49 | 50 | n = len(arr) 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | for i in range(n // 2 - 1, -1, -1): 59 | 60 | heapify(arr, n, i) 61 | 62 | 63 | # One by one extract elements 64 | 65 | 66 | for i in range(n - 1, 0, -1): 67 | 68 | (arr[i], arr[0]) = (arr[0], arr[i]) # swap 69 | 70 | heapify(arr, i, 0) 71 | 72 | 73 | # Driver code to test above 74 | 75 | 76 | arr = [12, 11, 13, 5, 6, 7, ] 77 | heapSort(arr) 78 | 79 | n = len(arr) 80 | 81 | print('Sorted array is') 82 | 83 | for i in range(n): 84 | 85 | print(arr[i]) 86 | -------------------------------------------------------------------------------- /Heap_Sort/Heap_sort.py: -------------------------------------------------------------------------------- 1 | # Heap Sort in python 2 | 3 | 4 | def heapify(arr, n, i): 5 | largest = i 6 | l = 2 * i + 1 7 | r = 2 * i + 2 8 | 9 | if l < n and arr[i] < arr[l]: 10 | largest = l 11 | 12 | if r < n and arr[largest] < arr[r]: 13 | largest = r 14 | 15 | 16 | if largest != i: 17 | arr[i], arr[largest] = arr[largest], arr[i] 18 | heapify(arr, n, largest) 19 | 20 | 21 | def heapSort(arr): 22 | n = len(arr) 23 | 24 | 25 | for i in range(n//2, -1, -1): 26 | heapify(arr, n, i) 27 | 28 | for i in range(n-1, 0, -1): 29 | 30 | arr[i], arr[0] = arr[0], arr[i] 31 | 32 | 33 | heapify(arr, i, 0) 34 | 35 | 36 | arr = [1, 12, 9, 5, 6, 10] 37 | heapSort(arr) 38 | n = len(arr) 39 | print("Sorted array is") 40 | for i in range(n): 41 | print("%d " % arr[i], end='') -------------------------------------------------------------------------------- /ImageToAscii/README.md: -------------------------------------------------------------------------------- 1 | # Image to ASCII Art 2 | This is a simple script that lets you convert an image to ascii text art. 3 | 4 | ## Usage 5 | 6 | * Only PIL package is required 7 | * Add path of your picture and set size of width and height by pixel. 8 | * Run `python imgtoascii.py` 9 | * Enjoy ASCII art! 10 | 11 | ## Result : 12 | 13 | B%B%B@@$$$$$$$$$$$$$$$$$$$$$$$$$$@@B%B% 14 | %B%@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@%B 15 | B%$$$$$$$$$$$$$$&obpdk*8$$$$$$$$$$$$$$% 16 | %@$$$$$$$$$$$#X)_i!ll!i?\Q%$$$$$$$$$$$@ 17 | B$$$$$$$$$$$m_;Il!!!!!!lll{h$$$$$$$$$$$ 18 | @$$$$$$$$$$#+ltU[l!!!!!!!!l[&$$$$$$$$$$ 19 | @$$$$$$$$$$wI[@$pl!!!!!!!!!IO$$$$$$$$$$ 20 | $$$$$$$$$$$wI]8$ml!!!!!!!!!lJ$$$$$$$$$$ 21 | $$$$$$$$$$$wll)x_!!!!!!!!!!lC$$$$$$$$$$ 22 | $$$$$$$$$$$wIlI;Illl!!!!!!!lC$$$$$$$$$$ 23 | $$$$$$$$$$$#zXXXXXXz_!!!!!!lC$$$$$$$$$$ 24 | $$$$$$8bqpppbbbbbbbd?l!!!!!lC&bbboB$$$$ 25 | $$$$$C?lllllllllllll!!!!!!!lLoYYYYQW$$$ 26 | $$$$Yll!!!!!!!!!!!!!!!!!!!!lLoYUUUYQ%$$ 27 | $$$ail!!!!!!!!!!!!!!!!!!!!!lLoYUUUUYb$$ 28 | $$$nI!!!!!!!!!!!!!!!!!!!!!!l0oYUUUUYQ@$ 29 | $$B}l!!!!!!!!!!!!!!!!!!!!!!lkhYUUUUUU&$ 30 | $$#~!!!!!!!!!!!!!!!!!!!!!!I\@mYUUUUUY*$ 31 | $$k!!!!!!!!!!lllllllllllI!\WWUUUUUUUYo$ 32 | $$dl!!!!!!!!l1uXYYYYYYYYCh@WLYUUUUUUYo$ 33 | $$dl!!!!!!!~0@%*aaaaaaaaakmUYUUUUUUUYo$ 34 | $$k!!!!!!!lL@dJYYYYYYYYYYYYUUUUUUUUUYo$ 35 | $$*~!!!!!l]BdYYUUUUUUUUUUUUUUUUUUUUUY*$ 36 | $$%]l!!!!lfBJYUUUUUUUUUUUUUUUUUUUUUUU&$ 37 | $$$tl!!!!luWYUUUUUUUUUUUUUUUUUUUUUUY0@$ 38 | $$$wl!!!!luMYUUUUUUUUUUUUUUUUUUUUUUYa$$ 39 | $$$B\I!!!luMYUUUUUUUUUUUUUUUUUUUUUYZ@$$ 40 | $$$$M)Ill;nMYUUUUUUUYYYYYYYYYYYYYJqB$$$ 41 | $$$$$%OunxZMYUUUUUUUa********ooo*&$$$$$ 42 | $$$$$$$$$$$#YUUUUUUUbhhhhhhhW$$$$$$$$$$ 43 | $$$$$$$$$$$#YUUUUUUUYYYYYYYYb$$$$$$$$$$ 44 | $$$$$$$$$$$#YUUUUUUUUUUUmOYYb$$$$$$$$$$ 45 | $$$$$$$$$$$#YUUUUUUUUUYd$@OYb$$$$$$$$$$ 46 | @$$$$$$$$$$MYUUUUUUUUUYh$$mYb$$$$$$$$$$ 47 | @$$$$$$$$$$@0YUUUUUUUUYChdUY*$$$$$$$$$$ 48 | B$$$$$$$$$$$&0YYYUUUUUUYYYUd@$$$$$$$$$$ 49 | %@$$$$$$$$$$$BaZCUYYYYYULqM$$$$$$$$$$$@ 50 | B%$$$$$$$$$$$$$$%&#**#M8B$$$$$$$$$$$$$% 51 | %B%@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@%B 52 | -------------------------------------------------------------------------------- /ImageToAscii/imgtoascii.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | 3 | ascii_characters_by_surface = r'`^\",:;Il!i~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$' 4 | 5 | def convert_to_ascii_art(image): 6 | ascii_art = [] 7 | (width, height) = image.size 8 | for y in range(0, height - 1): 9 | line = '' 10 | for x in range(0, width - 1): 11 | px = image.getpixel((x, y)) 12 | line += convert_pixel_to_character(px) 13 | ascii_art.append(line) 14 | return ascii_art 15 | 16 | 17 | def convert_pixel_to_character(pixel): 18 | (r, g, b) = pixel 19 | pixel_brightness = r + g + b 20 | max_brightness = 255 * 3 21 | brightness_weight = len(ascii_characters_by_surface) / max_brightness 22 | index = int(pixel_brightness * brightness_weight) - 1 23 | return ascii_characters_by_surface[index] 24 | 25 | 26 | def save_as_text(ascii_art): 27 | with open("image.txt", "w") as file: 28 | for line in ascii_art: 29 | file.write(line) 30 | file.write('\n') 31 | file.close() 32 | 33 | def main(): 34 | imdir = input('Please add your image direction carefully: ') 35 | imsize = input('Please set a value for width and height: ') 36 | image = Image.open(imdir) 37 | image = image.resize((int(imsize), int(imsize))) 38 | ascii_art = convert_to_ascii_art(image) 39 | save_as_text(ascii_art) 40 | print("Your ascii art is printed on image.txt file!") 41 | 42 | if __name__ == '__main__': 43 | main() -------------------------------------------------------------------------------- /ImageToAscii/py.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/ImageToAscii/py.jpg -------------------------------------------------------------------------------- /Insertion sort.C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | #include 6 | 7 | 8 | 9 | 10 | 11 | void insertionSort(int arr[], int n) 12 | 13 | { 14 | 15 | int i, key, j; 16 | 17 | for (i = 1; i < n; i++) 18 | 19 | { 20 | 21 | key = arr[i]; 22 | 23 | j = i - 1; 24 | 25 | 26 | 27 | 28 | 29 | while (j >= 0 && arr[j] > key) 30 | 31 | { 32 | 33 | arr[j + 1] = arr[j]; 34 | 35 | j = j - 1; 36 | 37 | } 38 | 39 | arr[j + 1] = key; 40 | 41 | } 42 | 43 | } 44 | 45 | 46 | 47 | 48 | 49 | void printArray(int arr[], int n) 50 | 51 | { 52 | 53 | int i; 54 | 55 | for (i = 0; i < n; i++) 56 | 57 | printf("%d ", arr[i]); 58 | 59 | printf("\n"); 60 | 61 | } 62 | 63 | 64 | 65 | 66 | 67 | int main() 68 | 69 | { 70 | 71 | int arr[] = {12, 11, 13, 5, 6}; 72 | 73 | int n = sizeof(arr) / sizeof(arr[0]); 74 | 75 | 76 | 77 | insertionSort(arr, n); 78 | 79 | printArray(arr, n); 80 | 81 | 82 | 83 | return 0; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /Insertion sort.py: -------------------------------------------------------------------------------- 1 | def insertionSort(arr): 2 | 3 | 4 | 5 | 6 | 7 | for i in range(1, len(arr)): 8 | 9 | 10 | 11 | key = arr[i] 12 | 13 | 14 | 15 | 16 | 17 | j = i-1 18 | 19 | while j >=0 and key < arr[j] : 20 | 21 | arr[j+1] = arr[j] 22 | 23 | j -= 1 24 | 25 | arr[j+1] = key 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | arr = [12, 11, 13, 5, 6] 34 | 35 | insertionSort(arr) 36 | 37 | lst = [] #empty list to store sorted elements 38 | 39 | print("Sorted array is : ") 40 | 41 | for i in range(len(arr)): 42 | 43 | lst.append(arr[i]) #appending the elements in sorted order 44 | 45 | print(lst) 46 | -------------------------------------------------------------------------------- /Jugglingalgorithm/Jugglingalgorithm.py: -------------------------------------------------------------------------------- 1 | import math 2 | def leftRotate(arr, d, n): 3 | for i in range(math.gcd(d, n)): 4 | temp = arr[i] 5 | j = i 6 | while 1: 7 | k = j + d 8 | if k >= n: 9 | k = k - n 10 | if k == i: 11 | break 12 | arr[j] = arr[k] 13 | j = k 14 | arr[j] = temp 15 | arr =list(map(int,input("ENTER ARRAY ELEMENTS ").split())) 16 | n = len(arr) 17 | no_of_rotations = 2 18 | 19 | print("Array Elements before rotation : ") 20 | print(*arr) 21 | leftRotate(arr, no_of_rotations, n ) 22 | print("\nArray Elements after rotation : ") 23 | print(*arr) 24 | -------------------------------------------------------------------------------- /Krishnangshu Paul/Krishnangshu Paul: -------------------------------------------------------------------------------- 1 | x = int(input("Enter the number of rows:")) 2 | y = int(input("Enter the number of columns:")) 3 | matrix = [] 4 | print("Enter the entries rowwise:") 5 | 6 | for i in range(x): 7 | a =[] 8 | for j in range(y): 9 | a.append(int(input())) 10 | matrix.append(a) 11 | 12 | b=[] 13 | 14 | for i in range(x): 15 | max1=0 16 | for j in range (y): 17 | if matrix[i][j]>max1: 18 | max1=matrix[i][j] 19 | b.append(max1) 20 | 21 | 22 | for i in range(y): 23 | max2=0 24 | for j in range (x): 25 | if matrix[i][j]>max1: 26 | max1=matrix[i][j] 27 | b.append(max2) 28 | 29 | 30 | for i in range(x): 31 | min1=matrix[i][j] 32 | for j in range (y): 33 | if matrix[i][j] arr[j] and lis[i]< lis[j] + 1 : 9 | lis[i] = lis[j]+1 10 | 11 | maximum = 0 12 | 13 | for i in range(n): 14 | maximum = max(maximum, lis[i]) 15 | 16 | return maximum 17 | 18 | arr = [10, 22, 9, 33, 21, 50, 41, 60] 19 | print "Length of lis is", lis(arr) 20 | -------------------------------------------------------------------------------- /MaxPeaks/MaxPeaks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | int n; 7 | cin>>n; 8 | int arr[n]; 9 | for(int i=0;i>arr[i]; 11 | } 12 | vectorpeaks(n,0); 13 | int peak=0; 14 | for(int i=1;iarr[i-1]&&arr[i]>arr[i+1]){ 16 | peak++; 17 | } 18 | peaks[i]=peak; 19 | } 20 | peaks[n-1]=peak; 21 | int k; 22 | cin>>k; 23 | int m=arr[k-1]; 24 | int l=0; 25 | for(int i=k;i", simulate) 47 | window.mainloop() 48 | -------------------------------------------------------------------------------- /N_queen/n_queen.py: -------------------------------------------------------------------------------- 1 | global N 2 | N = 4 3 | 4 | def printSolution(board): 5 | for i in range(N): 6 | for j in range(N): 7 | print (board[i][j],end=' ') 8 | print() 9 | 10 | 11 | def isSafe(board, row, col): 12 | 13 | for i in range(col): 14 | if board[row][i] == 1: 15 | return False 16 | 17 | for i, j in zip(range(row, -1, -1), range(col, -1, -1)): 18 | if board[i][j] == 1: 19 | return False 20 | 21 | for i, j in zip(range(row, N, 1), range(col, -1, -1)): 22 | if board[i][j] == 1: 23 | return False 24 | 25 | return True 26 | 27 | def n_queen(board, col): 28 | if col >= N: 29 | return True 30 | 31 | for i in range(N): 32 | 33 | if isSafe(board, i, col): 34 | board[i][col] = 1 35 | 36 | if n_queen(board, col + 1) == True: 37 | return True 38 | 39 | board[i][col] = 0 40 | 41 | return False 42 | 43 | 44 | def solve(): 45 | board = [ [0, 0, 0, 0], 46 | [0, 0, 0, 0], 47 | [0, 0, 0, 0], 48 | [0, 0, 0, 0] 49 | ] 50 | 51 | if n_queen(board, 0) == False: 52 | print ("Solution does not exist") 53 | return False 54 | 55 | printSolution(board) 56 | return True 57 | 58 | # driver program to test above function 59 | solve() -------------------------------------------------------------------------------- /PainterPartitionProblem.java: -------------------------------------------------------------------------------- 1 | // Java Program for The painter's partition problem 2 | import java.util.*; 3 | import java.io.*; 4 | 5 | class GFG 6 | { 7 | // function to calculate sum between two indices 8 | // in array 9 | static int sum(int arr[], int from, int to) 10 | { 11 | int total = 0; 12 | for (int i = from; i <= to; i++) 13 | total += arr[i]; 14 | return total; 15 | } 16 | 17 | // for n boards and k partitions 18 | static int partition(int arr[], int n, int k) 19 | { 20 | // base cases 21 | if (k == 1) // one partition 22 | return sum(arr, 0, n - 1); 23 | if (n == 1) // one board 24 | return arr[0]; 25 | 26 | int best = Integer.MAX_VALUE; 27 | 28 | // find minimum of all possible maximum 29 | // k-1 partitions to the left of arr[i], 30 | // with i elements, put k-1 th divider 31 | // between arr[i-1] & arr[i] to get k-th 32 | // partition 33 | for (int i = 1; i <= n; i++) 34 | best = Math.min(best, Math.max(partition(arr, i, k - 1), 35 | sum(arr, i, n - 1))); 36 | 37 | return best; 38 | } 39 | 40 | // Driver code 41 | public static void main(String args[]) 42 | { 43 | int arr[] = { 10, 20, 60, 50, 30, 40 }; 44 | 45 | // Calculate size of array. 46 | int n = arr.length; 47 | int k = 3; 48 | System.out.println(partition(arr, n, k)); 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /PalindromeString.py: -------------------------------------------------------------------------------- 1 | # Program to check if a string is palindrome or not 2 | 3 | my_str = 'aIbohPhoBiA' 4 | 5 | # make it suitable for caseless comparison 6 | my_str = my_str.casefold() 7 | 8 | # reverse the string 9 | rev_str = reversed(my_str) 10 | 11 | # check if the string is equal to its reverse 12 | if list(my_str) == list(rev_str): 13 | print("The string is a palindrome.") 14 | else: 15 | print("The string is not a palindrome.") 16 | -------------------------------------------------------------------------------- /Password_genertaor.py: -------------------------------------------------------------------------------- 1 | import random 2 | passlen = int(input("enter the length of password")) 3 | s="abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?" 4 | p = "".join(random.sample(s,passlen )) 5 | print (p) 6 | -------------------------------------------------------------------------------- /Pattern(1)/Pattern.9cpp: -------------------------------------------------------------------------------- 1 | // Factorial of n = 1*2*3*...*n 2 | 3 | #include 4 | using namespace std; 5 | 6 | int factorial(int); 7 | 8 | int main() { 9 | int n, result; 10 | 11 | cout << "Enter a non-negative number: "; 12 | cin >> n; 13 | 14 | result = factorial(n); 15 | cout << "Factorial of " << n << " = " << result; 16 | return 0; 17 | } 18 | 19 | int factorial(int n) { 20 | if (n > 1) { 21 | return n * factorial(n - 1); 22 | } else { 23 | return 1; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Pattern/Pattern: -------------------------------------------------------------------------------- 1 | n = 8 2 | 3 | for r in range(1, n): 4 | 5 | digit = 1 6 | 7 | for m in range(n, 0, -1): 8 | 9 | if m > r: 10 | 11 | print(" ", end=' ') 12 | 13 | else: 14 | 15 | print(digit, end=' ') 16 | 17 | digit += 1 18 | 19 | print("") 20 | -------------------------------------------------------------------------------- /Pattern21.py: -------------------------------------------------------------------------------- 1 | # Python program to print Fullpyramid of numbers 2 | # 1 3 | # 2 3 2 4 | # 3 4 5 4 3 5 | # 4 5 6 7 6 5 4 6 | # 5 6 7 8 9 8 7 6 5 7 | 8 | 9 | rows = int(input("Enter number of rows: ")) 10 | 11 | k = 0 12 | count=0 13 | count1=0 14 | 15 | for i in range(1, rows+1): 16 | for space in range(1, (rows-i)+1): 17 | print(" ", end="") 18 | count+=1 19 | 20 | while k!=((2*i)-1): 21 | if count<=rows-1: 22 | print(i+k, end=" ") 23 | count+=1 24 | else: 25 | count1+=1 26 | print(i+k-(2*count1), end=" ") 27 | k += 1 28 | 29 | count1 = count = k = 0 30 | print() 31 | 32 | -------------------------------------------------------------------------------- /Pong Game/pong.py: -------------------------------------------------------------------------------- 1 | import turtle as t 2 | 3 | playerAscore=0 4 | 5 | playerBscore=0 6 | 7 | 8 | 9 | #create a window and declare a variable called window and call the screen() 10 | 11 | window=t.Screen() 12 | 13 | window.title("The Pong Game") 14 | 15 | window.bgcolor("green") 16 | 17 | window.setup(width=800,height=600) 18 | 19 | window.tracer(0) 20 | 21 | 22 | 23 | #Creating the left paddle 24 | 25 | leftpaddle=t.Turtle() 26 | 27 | leftpaddle.speed(0) 28 | 29 | leftpaddle.shape("square") 30 | 31 | leftpaddle.color("white") 32 | 33 | leftpaddle.shapesize(stretch_wid=5,stretch_len=1) 34 | 35 | leftpaddle.penup() 36 | 37 | leftpaddle.goto(-350,0) 38 | 39 | 40 | 41 | #Creating the right paddle 42 | 43 | rightpaddle=t.Turtle() 44 | 45 | rightpaddle.speed(0) 46 | 47 | rightpaddle.shape("square") 48 | 49 | rightpaddle.color("white") 50 | 51 | rightpaddle.shapesize(stretch_wid=5,stretch_len=1) 52 | 53 | rightpaddle.penup() 54 | 55 | rightpaddle.goto(-350,0) 56 | 57 | 58 | 59 | #Code for creating the ball 60 | 61 | ball=t.Turtle() 62 | 63 | ball.speed(0) 64 | 65 | ball.shape("circle") 66 | 67 | ball.color("red") 68 | 69 | ball.penup() 70 | 71 | ball.goto(5,5) 72 | 73 | ballxdirection=0.2 74 | 75 | ballydirection=0.2 76 | 77 | 78 | 79 | #Code for creating pen for scorecard update 80 | 81 | pen=t.Turtle() 82 | 83 | pen.speed(0) 84 | 85 | pen.color("Blue") 86 | 87 | pen.penup() 88 | 89 | pen.hideturtle() 90 | 91 | pen.goto(0,260) 92 | 93 | pen.write("score",align="center",font=('Arial',24,'normal')) 94 | 95 | 96 | 97 | #code for moving the leftpaddle 98 | 99 | def leftpaddleup(): 100 | 101 | y=leftpaddle.ycor() 102 | 103 | y=y+90 104 | 105 | leftpaddle.sety(y) 106 | 107 | 108 | 109 | def leftpaddledown(): 110 | 111 | y=leftpaddle.ycor() 112 | 113 | y=y+90 114 | 115 | leftpaddle.sety(y) 116 | 117 | 118 | 119 | #code for moving the rightpaddle 120 | 121 | def rightpaddleup(): 122 | 123 | y=rightpaddle.ycor() 124 | 125 | y=y+90 126 | 127 | rightpaddle.sety(y) 128 | 129 | 130 | 131 | def rightpaddledown(): 132 | 133 | y=rightpaddle.ycor() 134 | 135 | y=y+90 136 | 137 | rightpaddle.sety(y) 138 | 139 | 140 | 141 | #Assign keys to play 142 | 143 | window.listen() 144 | 145 | window.onkeypress(leftpaddleup,'w') 146 | 147 | window.onkeypress(leftpaddledown,'s') 148 | 149 | window.onkeypress(rightpaddleup,'Up') 150 | 151 | window.onkeypress(rightpaddledown,'Down') 152 | 153 | 154 | 155 | while True: 156 | 157 | window.update() 158 | 159 | 160 | 161 | #moving the ball 162 | 163 | ball.setx(ball.xcor()+ballxdirection) 164 | 165 | ball.sety(ball.ycor()+ballxdirection) 166 | 167 | 168 | 169 | #border set up 170 | 171 | if ball.ycor()>290: 172 | 173 | ball.sety(290) 174 | 175 | ballydirection=ballydirection*-1 176 | 177 | if ball.ycor()<-290: 178 | 179 | ball.sety(-290) 180 | 181 | ballydirection=ballydirection*-1 182 | 183 | 184 | 185 | if ball.xcor() > 390: 186 | 187 | ball.goto(0,0) 188 | 189 | ball_dx = ball_dx * -1 190 | 191 | player_a_score = player_a_score + 1 192 | 193 | pen.clear() 194 | 195 | pen.write("Player A: {} Player B: {} ".format(player_a_score,player_b_score),align="center",font=('Monaco',24,"normal")) 196 | 197 | os.system("afplay wallhit.wav&") 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | if(ball.xcor()) < -390: # Left width paddle Border 206 | 207 | ball.goto(0,0) 208 | 209 | ball_dx = ball_dx * -1 210 | 211 | player_b_score = player_b_score + 1 212 | 213 | pen.clear() 214 | 215 | pen.write("Player A: {} Player B: {} ".format(player_a_score,player_b_score),align="center",font=('Monaco',24,"normal")) 216 | 217 | os.system("afplay wallhit.wav&") 218 | 219 | 220 | 221 | # Handling the collisions with paddles. 222 | 223 | 224 | 225 | if(ball.xcor() > 340) and (ball.xcor() < 350) and (ball.ycor() < rightpaddle.ycor() + 40 and ball.ycor() > rightpaddle.ycor() - 40): 226 | 227 | ball.setx(340) 228 | 229 | ball_dx = ball_dx * -1 230 | 231 | os.system("afplay paddle.wav&") 232 | 233 | 234 | 235 | if(ball.xcor() < -340) and (ball.xcor() > -350) and (ball.ycor() < leftpaddle.ycor() + 40 and ball.ycor() > leftpaddle.ycor() - 40): 236 | 237 | ball.setx(-340) 238 | 239 | ball_dx = ball_dx * -1 240 | 241 | os.system("afplay paddle.wav&") 242 | -------------------------------------------------------------------------------- /Pyramid/Pyramid.py: -------------------------------------------------------------------------------- 1 | x = int(input("Enter the number of rows is ")) 2 | for i in range(1,x+1): 3 | for j in range(x-i): 4 | print("",end=" ") 5 | for k in range(i): 6 | print(i,end= " ") 7 | for l in range(i-1): 8 | print(i,end=" ") 9 | print("") 10 | -------------------------------------------------------------------------------- /Python content based recommendation system/quadratic.py: -------------------------------------------------------------------------------- 1 | import math 2 | a = float(input("Enter the first coefficient: ")) 3 | b = float(input("Enter the second coefficient: ")) 4 | c = float(input("Enter the third coefficient: ")) 5 | if (a!=0.0): 6 | d = (b*b)-(4*a*c) 7 | if (d==0.0): 8 | print("The roots are real and equal.") 9 | r = -b/(2*a) 10 | print("The roots are ", r,"and", r) 11 | elif(d>0.0): 12 | print("The roots are real and distinct.") 13 | r1 = (-b+(math.sqrt(d)))/(2*a) 14 | r2 = (-b-(math.sqrt(d)))/(2*a) 15 | print("The root1 is: ", r1) 16 | print("The root2 is: ", r2) 17 | else: 18 | print("The roots are imaginary.") 19 | rp = -b/(2*a) 20 | ip = math.sqrt(-d)/(2*a) 21 | print("The root1 is: ", rp, "+ i",ip) 22 | print("The root2 is: ", rp, "- i",ip) 23 | else: 24 | print("Not a quadratic equation.") 25 | -------------------------------------------------------------------------------- /Python/Alarm clock.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from playsound import playsound 3 | alarm_time = input("Enter the time of alarm to be set:HH:MM:SS\n") 4 | alarm_hour=alarm_time[0:2] 5 | alarm_minute=alarm_time[3:5] 6 | alarm_seconds=alarm_time[6:8] 7 | alarm_period = alarm_time[9:11].upper() 8 | print("Setting up alarm..") 9 | while True: 10 | now = datetime.now() 11 | current_hour = now.strftime("%I") 12 | current_minute = now.strftime("%M") 13 | current_seconds = now.strftime("%S") 14 | current_period = now.strftime("%p") 15 | if(alarm_period==current_period): 16 | if(alarm_hour==current_hour): 17 | if(alarm_minute==current_minute): 18 | if(alarm_seconds==current_seconds): 19 | print("Wake Up!") 20 | playsound('audio.mp3') 21 | break 22 | -------------------------------------------------------------------------------- /Python/Music Player.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | import tkinter as tkr 3 | from tkinter.filedialog import askdirectory 4 | import os 5 | 6 | music_player = tkr.Tk() 7 | music_player.title("My Music Player") 8 | music_player.geometry("450x350") 9 | directory = askdirectory() 10 | os.chdir(directory) 11 | song_list = os.listdir() 12 | 13 | play_list = tkr.Listbox(music_player, font="Helvetica 12 bold", bg='yellow', selectmode=tkr.SINGLE) 14 | for item in song_list: 15 | pos = 0 16 | play_list.insert(pos, item) 17 | pos += 1 18 | pygame.init() 19 | pygame.mixer.init() 20 | -------------------------------------------------------------------------------- /Python/Music player.py: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | 5 | class Graph { 6 | private int V; //number of nodes 7 | 8 | private LinkedList adj[]; //adjacency list 9 | 10 | public Graph(int v) 11 | { 12 | V = v; 13 | adj = new LinkedList[v]; 14 | for (int i = 0; i < v; ++i) 15 | { 16 | adj[i] = new LinkedList(); 17 | } 18 | 19 | void addEdge(int v, int w) 20 | { 21 | adj[v].add(w); //adding an edge to the adjacency list (edges are bidirectional in this example) 22 | } 23 | 24 | 25 | void DFSUtil(int vertex, boolean nodes[]) 26 | { 27 | 28 | nodes[vertex] = true; //mark the node as explored 29 | System.out.print(vertex + " "); 30 | int a = 0; 31 | 32 | for (int i = 0; i < adj[vertex].size(); i++) //iterate through the linked list and then propagate to the next few nodes 33 | { 34 | a = adj[vertex].get(i); 35 | if (!nodes[a]) //only propagate to next nodes which haven't been explored 36 | { 37 | DFSUtil(a, nodes); 38 | } 39 | } 40 | } 41 | 42 | void DFS(int v) 43 | { 44 | boolean already[] = new boolean[V]; //initialize a new boolean array to store the details of explored nodes 45 | DFSUtil(v, already); 46 | } 47 | 48 | public static void main(String args[]) 49 | { 50 | Graph g = new Graph(6); 51 | 52 | g.addEdge(0, 1); 53 | g.addEdge(0, 2); 54 | g.addEdge(1, 0); 55 | g.addEdge(1, 3); 56 | g.addEdge(2, 0); 57 | g.addEdge(2, 3); 58 | g.addEdge(3, 4); 59 | g.addEdge(3, 5); 60 | g.addEdge(4, 3); 61 | g.addEdge(5, 3); 62 | 63 | System.out.println( 64 | "Following is Depth First Traversal: "); 65 | 66 | g.DFS(0); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Python/Python.py: -------------------------------------------------------------------------------- 1 | # Python program to display all the prime numbers within an interval 2 | 3 | lower = 900 4 | 5 | upper = 1000 6 | 7 | print("Prime numbers between", lower, "and", upper, "are:") 8 | 9 | for num in range(lower, upper + 1): 10 | 11 | # all prime numbers are greater than 1 12 | 13 | if num > 1: 14 | 15 | for i in range(2, num): 16 | 17 | if (num % i) == 0: 18 | 19 | break 20 | 21 | else: 22 | 23 | print(num) 24 | -------------------------------------------------------------------------------- /Python/QR-Code-Generator.py: -------------------------------------------------------------------------------- 1 | # Import QRCode from pyqrcode 2 | import pyqrcode 3 | import png 4 | from pyqrcode import QRCode 5 | 6 | 7 | # String which represents the QR code 8 | s = "www.geeksforgeeks.org" 9 | 10 | # Generate QR code 11 | url = pyqrcode.create(s) 12 | 13 | # Create and save the svg file naming "myqr.svg" 14 | url.svg("myqr.svg", scale = 8) 15 | 16 | # Create and save the png file naming "myqr.png" 17 | url.png('myqr.png', scale = 6) 18 | -------------------------------------------------------------------------------- /Python/clickeventdrivenprogram.py: -------------------------------------------------------------------------------- 1 | '''Program to demonstrate event driven programming''' 2 | import turtle 3 | turtle.setup(500,500) 4 | wn = turtle.Screen() 5 | wn.title("Multi mouse clicks!") 6 | wn.bgcolor("yellow") 7 | goku = turtle.Turtle() 8 | goku.color("orange") 9 | goku.shape("turtle") 10 | goku.pensize(4) 11 | vegeta = turtle.Turtle() 12 | vegeta.color("blue") 13 | vegeta.shape("turtle") 14 | vegeta.forward(100) 15 | def handler_for_goku(x, y): 16 | wn.title("goku clicked at {0}, {1}".format(x, y)) 17 | goku.left(45) 18 | goku.forward(75) 19 | def handler_for_vegeta(x, y): 20 | wn.title("vegeta clicked at {0}, {1}".format(x, y)) 21 | vegeta.right(60) 22 | vegeta.forward(60) 23 | 24 | #On mouse click the turtle associated with this object would move 25 | goku.onclick(handler_for_goku) 26 | vegeta.onclick(handler_for_vegeta) 27 | wn.mainloop() 28 | 29 | '''Code provided by Akshaj Vishwanathan''' 30 | -------------------------------------------------------------------------------- /Python/factorial.py: -------------------------------------------------------------------------------- 1 | def fact(n): 2 | if n==1: 3 | f=1 4 | else: 5 | f = n * fact(n-1) 6 | return f 7 | num = int(input("Enter an integer: ")) 8 | result = fact(num) 9 | print("The factorial of", num, " is: ", result) 10 | -------------------------------------------------------------------------------- /QR Code Generator/QR Code Generator.py: -------------------------------------------------------------------------------- 1 | import pyqrcode 2 | import png 3 | 4 | your_link = "g" 5 | 6 | url = pyqrcode.create(your_link) 7 | 8 | img = "cuiatk.png" 9 | 10 | url.png(img, scale=10) 11 | -------------------------------------------------------------------------------- /Radix_Sorting/Radix_sorting.py: -------------------------------------------------------------------------------- 1 | # Radix sort in Python 2 | 3 | def countingSort(array, place): 4 | size = len(array) 5 | output = [0] * size 6 | count = [0] * 10 7 | 8 | for i in range(0, size): 9 | index = array[i] // place 10 | count[index % 10] += 1 11 | 12 | 13 | for i in range(1, 10): 14 | count[i] += count[i - 1] 15 | 16 | 17 | i = size - 1 18 | while i >= 0: 19 | index = array[i] // place 20 | output[count[index % 10] - 1] = array[i] 21 | count[index % 10] -= 1 22 | i -= 1 23 | 24 | for i in range(0, size): 25 | array[i] = output[i] 26 | 27 | 28 | 29 | def radixSort(array): 30 | 31 | max_element = max(array) 32 | 33 | 34 | place = 1 35 | while max_element // place > 0: 36 | countingSort(array, place) 37 | place *= 10 38 | 39 | 40 | data = [121, 432, 564, 23, 1, 45, 788] 41 | radixSort(data) 42 | print(data) -------------------------------------------------------------------------------- /Ram Kaminwar/ram.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | print('Hello') -------------------------------------------------------------------------------- /RecursiveFactorial.py: -------------------------------------------------------------------------------- 1 | def recur_factorial(n): 2 | if n == 1: 3 | return n 4 | else: 5 | return n*recur_factorial(n-1) 6 | 7 | num = 7 8 | 9 | if num < 0: 10 | print("Sorry, factorial does not exist for negative numbers") 11 | elif num == 0: 12 | print("The factorial of 0 is 1") 13 | else: 14 | print("The factorial of", num, "is", recur_factorial(num)) 15 | -------------------------------------------------------------------------------- /Reverse.py: -------------------------------------------------------------------------------- 1 | num = 1234 2 | reversed_num = 0 3 | 4 | while num != 0: 5 | digit = num % 10 6 | reversed_num = reversed_num * 10 + digit 7 | num //= 10 8 | 9 | print("Reversed Number: " + str(reversed_num)) 10 | -------------------------------------------------------------------------------- /Richard Nikolas/checkPrimeOnInterval.py: -------------------------------------------------------------------------------- 1 | print('\x1b[1;37;45m' + '----------------------------------------------' + '\x1b[0m') 2 | print('\x1b[1;37;45m' + ' Showing all prime numbers within an interval ' + '\x1b[0m') 3 | print('\x1b[1;37;45m' + '----------------------------------------------' + '\x1b[0m') 4 | print('\n') 5 | 6 | lower = 0 7 | upper = 0 8 | 9 | while upper <= lower: 10 | lower = int(input('Enter lower number: ')) 11 | upper = int(input('Enter upper number: ')) 12 | print('\n') 13 | 14 | if upper > lower: 15 | print('\x1b[5;30;42m' + ' Prime numbers between', lower, 'and', upper, 'are: ' + '\x1b[0m') 16 | 17 | for num in range(lower, upper + 1): 18 | if num > 1: 19 | for i in range(2, num): 20 | if (num % i) == 0: 21 | break 22 | else: 23 | print(num) 24 | else: 25 | print('\x1b[0;37;41m' + '** Upper must be greater than Lower! **' + '\x1b[0m') 26 | print('\n') 27 | -------------------------------------------------------------------------------- /Rock, Paper and Scissors Game with Python.py: -------------------------------------------------------------------------------- 1 | import random 2 | choices = ["Rock", "Paper", "Scissors"] 3 | computer = random.choice(choices) 4 | player = False 5 | cpu_score = 0 6 | player_score = 0 7 | while True: 8 | player = input("Rock, Paper or Scissors?").capitalize() 9 | ## Conditions of Rock,Paper and Scissors 10 | if player == computer: 11 | print("Tie!") 12 | elif player == "Rock": 13 | if computer == "Paper": 14 | print("You lose!", computer, "covers", player) 15 | cpu_score+=1 16 | else: 17 | print("You win!", player, "smashes", computer) 18 | player_score+=1 19 | elif player == "Paper": 20 | if computer == "Scissors": 21 | print("You lose!", computer, "cut", player) 22 | cpu_score+=1 23 | else: 24 | print("You win!", player, "covers", computer) 25 | player_score+=1 26 | elif player == "Scissors": 27 | if computer == "Rock": 28 | print("You lose...", computer, "smashes", player) 29 | cpu_score+=1 30 | else: 31 | print("You win!", player, "cut", computer) 32 | player_score+=1 33 | elif player=='End': 34 | print("Final Scores:") 35 | print(f"CPU:{cpu_score}") 36 | print(f"Plaer:{player_score}") 37 | break 38 | -------------------------------------------------------------------------------- /RockPaperScissor/RockPaperScissor.py: -------------------------------------------------------------------------------- 1 | import random 2 | print("Hi!",input("What is Your good Name? ")) 3 | user = 0; computer = 0 4 | l = ["rock","paper","scissor","q"] 5 | while True: 6 | user_sel = input("Please Select Either of Rock/Paper/Scissor or Q to Quit ").lower() 7 | a = random.randint(0,2) 8 | computer_sel = l[a] 9 | if user_sel == "q": 10 | break 11 | elif user_sel not in l: 12 | print("Invalid Input!!, Try again") 13 | continue 14 | print("Computer Chose:",computer_sel) 15 | if user_sel == "rock" and computer_sel == "scissor": 16 | print("Congrats! You Win") 17 | user+=1 18 | elif user_sel == "paper" and computer_sel == "rock": 19 | print("Congrats! You Win") 20 | user += 1 21 | elif user_sel == "scissor" and computer_sel == "paper": 22 | print("Congrats! You Win") 23 | user += 1 24 | elif user_sel == computer_sel: 25 | print("Ohh! Its a Draw") 26 | else: 27 | print("OOPS! I think you Lost") 28 | computer+=1 29 | print("You Won", user, "times.") 30 | print("Computer Won", computer, "times.") 31 | print("Thanks For Playing, Have a Nice Day :)") 32 | -------------------------------------------------------------------------------- /Rolling Dice Simulator.py: -------------------------------------------------------------------------------- 1 | import random 2 | while True: 3 | print("Press 1 if you want to roll a dice else just enter any key to exit from program") 4 | user = input("Press key: ") 5 | if user=="1": 6 | print("Value on dice is : "+random.randint(1,6)) 7 | else: 8 | break 9 | print("Program terminated '_'") 10 | -------------------------------------------------------------------------------- /Rot13/rot13.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | alphabet = 'abcdefghijklmnopqrstuvwxyz' 5 | def encrypt(text): 6 | text = text.lower() 7 | result = 'Your Output is : ' 8 | for char in text: 9 | if char.isalpha(): 10 | result += alphabet[(alphabet.index(char) + 13) % 26] 11 | else: 12 | result += char 13 | return result 14 | 15 | def decrypt(text): 16 | text = text.lower() 17 | result = 'Your Output is : ' 18 | for char in text: 19 | if char.isalpha(): 20 | result += alphabet[(alphabet.index(char) - 13) % 26] 21 | else: 22 | result += char 23 | return result 24 | 25 | user_option = input("Enter Option: \n1. ROT13 Encryption\n2. ROT13 Decryption\n\nYour choice :") 26 | if (user_option == "1"): 27 | user_input = input("Enter the text: ") 28 | print(encrypt(user_input)) 29 | 30 | elif (user_option == "2"): 31 | user_input = input("Enter the text: ") 32 | print(decrypt(user_input)) 33 | else: 34 | print("Enter correct option") 35 | -------------------------------------------------------------------------------- /Runner -.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner -.lnk -------------------------------------------------------------------------------- /Runner Game/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Runner Game/.idea/Pygame building blocks.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Runner Game/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /Runner Game/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Runner Game/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Runner Game/Runner - Shortcut.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/Runner - Shortcut.lnk -------------------------------------------------------------------------------- /Runner Game/audio/jump.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/audio/jump.mp3 -------------------------------------------------------------------------------- /Runner Game/audio/music.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/audio/music.wav -------------------------------------------------------------------------------- /Runner Game/font/Pixeltype.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/font/Pixeltype.ttf -------------------------------------------------------------------------------- /Runner Game/graphics/Fly/Fly1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Fly/Fly1.png -------------------------------------------------------------------------------- /Runner Game/graphics/Fly/Fly2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Fly/Fly2.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 10.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 11.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 12.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 2.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 3.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 4.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 5.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 6.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 7.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 8.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/Layer 9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/Layer 9.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/jump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/jump.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/layer 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/layer 1.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/player_stand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/player_stand.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/player_walk_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/player_walk_1.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/player_walk_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/player_walk_2.png -------------------------------------------------------------------------------- /Runner Game/graphics/Player/stickmanrun.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Player/stickmanrun.zip -------------------------------------------------------------------------------- /Runner Game/graphics/Sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/Sky.png -------------------------------------------------------------------------------- /Runner Game/graphics/city.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/city.png -------------------------------------------------------------------------------- /Runner Game/graphics/endlessparallax_01_bybcsilva.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/endlessparallax_01_bybcsilva.png -------------------------------------------------------------------------------- /Runner Game/graphics/endlessparallax_02_bybcsilva.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/endlessparallax_02_bybcsilva.png -------------------------------------------------------------------------------- /Runner Game/graphics/endlessparallax_03_bybcsilva.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/endlessparallax_03_bybcsilva.png -------------------------------------------------------------------------------- /Runner Game/graphics/endlessparallax_04_bybcsilva.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/endlessparallax_04_bybcsilva.png -------------------------------------------------------------------------------- /Runner Game/graphics/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/ground.png -------------------------------------------------------------------------------- /Runner Game/graphics/new-btn-bg-635611.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/new-btn-bg-635611.png -------------------------------------------------------------------------------- /Runner Game/graphics/snail/snail1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/snail/snail1.png -------------------------------------------------------------------------------- /Runner Game/graphics/snail/snail2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/snail/snail2.png -------------------------------------------------------------------------------- /Runner Game/graphics/spritesheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Runner Game/graphics/spritesheet.png -------------------------------------------------------------------------------- /Script - Convert to Gray Image/grayImg.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import os 3 | import tkinter as tk 4 | from tkinter import filedialog 5 | 6 | root = tk.Tk() 7 | root.withdraw() 8 | file_path = filedialog.askopenfilename(title = "Select image to start with") # Choose image 9 | 10 | file = file_path.split("/")[-1] 11 | print(file) 12 | img = cv2.imread(file_path) # reads image 13 | grayImg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # recoloring image to gray 14 | 15 | folder_selected = filedialog.askdirectory(title = "Select directory to save image") # Select directory to store gray image 16 | 17 | image_name = os.path.join(folder_selected, f"gray-{file}") 18 | print(f"Saving image at {folder_selected} as gray-{file}") 19 | 20 | cv2.imwrite(image_name, grayImg) # saving gray image -------------------------------------------------------------------------------- /Script - Convert to Gray Image/requirements.txt: -------------------------------------------------------------------------------- 1 | opencv-python 2 | tkinter 3 | -------------------------------------------------------------------------------- /Script - Convert to Gray Image/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Script - Convert to Gray Image/test.jpg -------------------------------------------------------------------------------- /Script - Random Song Player/randomSongPlayer.py: -------------------------------------------------------------------------------- 1 | import random, os 2 | from tkinter import filedialog 3 | 4 | music_dir = filedialog.askdirectory(title = "Select directory to play song from") # Select directory to play song from 5 | songs = os.listdir(music_dir) # Make a list of all available files in selected directory 6 | song = random.randint(0,len(songs)) # Generate a random index to play random song 7 | print(f"Now playing {songs[song]}...") # Prints The Song Name 8 | os.startfile(os.path.join(music_dir, songs[song])) # Play song -------------------------------------------------------------------------------- /Script - Random Song Player/requirements.txt: -------------------------------------------------------------------------------- 1 | tkinter -------------------------------------------------------------------------------- /Shivam Garg/fibonacci.py: -------------------------------------------------------------------------------- 1 | def print_fibonacci(num): 2 | print(f"Fibonacci series for first {num} numbers: ", end=" ") 3 | x, y = 0, 1 4 | if num == 1: 5 | print(x) 6 | elif num == 2: 7 | print(x, y) 8 | else: 9 | print(x, y, end=" ") 10 | for i in range(3, num+1): 11 | x, y = y, x+y 12 | print(y, end=" ") 13 | 14 | 15 | if __name__ == "__main__": 16 | try: 17 | n = int(input("Please enter an integer to print first n Fibonacci numbers")) 18 | if n == 0: 19 | raise ValueError('0 not a valid input') 20 | print_fibonacci(n) 21 | except ValueError as e: 22 | print("Rerun the program") 23 | -------------------------------------------------------------------------------- /Shivam Mishra/NthStair.py: -------------------------------------------------------------------------------- 1 | def stair(n): 2 | # base condition 3 | if(n==1): 4 | return 1 5 | if(n==2): 6 | return 2 7 | # recuesive call 8 | call1=stair(n-1) 9 | call2=stair(n-2) 10 | # samll calculation 11 | smallcal=call1+call2 12 | return smallcal 13 | 14 | n=int(input("Input the stair no.you want to reach: ")) 15 | s=stair(n) 16 | print(s) 17 | -------------------------------------------------------------------------------- /Shivam Mishra/subsequence_of_Array.py: -------------------------------------------------------------------------------- 1 | def subsequenceArray(ind,n,arr,list1): 2 | # Base Condition 3 | if(ind==n): 4 | for i in list1: 5 | print(i,end=" ") 6 | if(len(list1)==0): 7 | print("{}") 8 | print("\n") 9 | return 10 | # Pick the element 11 | list1.append(arr[ind]) 12 | # increase index by 1 and call function 13 | subsequenceArray(ind+1,n,arr,list1) 14 | #when base condition occur for uper recursion return and Clear the list 15 | list1.pop() 16 | # call next recursion 17 | subsequenceArray(ind+1,n,arr,list1) 18 | 19 | list1=[] 20 | arr=[3,1,2] 21 | n=len(arr) 22 | subsequenceArray(0,n,arr,list1) 23 | -------------------------------------------------------------------------------- /Shivam Mishra/validateSubsequence.py: -------------------------------------------------------------------------------- 1 | # validate an array is subsequence of other array 2 | def validateSubsequence(mainArray,seqArray): 3 | check=0 4 | for ele in mainArray: 5 | if(seqArray[check]==ele): 6 | check+=1 7 | if (check==len(seqArray)): 8 | break 9 | return check==len(seqArray) 10 | respose = validateSubsequence([3,1,2],[2,1]) 11 | print(respose) 12 | -------------------------------------------------------------------------------- /Siddhesh.py: -------------------------------------------------------------------------------- 1 | activities = [["A1", 0, 6],["A2", 3, 4],["A3", 1, 2],["A4", 5, 8],["A5", 5, 7],["A6", 8, 9]] 2 | def printMaxActivities(activities): 3 | activities.sort(key=lambda x: x[2]) 4 | i = 0 5 | firstA = activities[i][0] 6 | print(firstA) 7 | for j in range(len(activities)): 8 | if activities[j][1] > activities[i][2]: 9 | print(activities[j][0]) 10 | i = j 11 | printMaxActivities(activities) 12 | -------------------------------------------------------------------------------- /SieveOfEratosthenes.py: -------------------------------------------------------------------------------- 1 | def SieveOfEratosthenes(num): 2 | prime = [True for i in range(num+1)] 3 | 4 | p = 2 5 | while (p * p <= num): 6 | 7 | 8 | if (prime[p] == True): 9 | 10 | 11 | for i in range(p * p, num+1, p): 12 | prime[i] = False 13 | p += 1 14 | 15 | 16 | for p in range(2, num+1): 17 | if prime[p]: 18 | print(p) 19 | 20 | 21 | 22 | if __name__ == '__main__': 23 | num = 50 24 | print("Following are the prime numbers smaller"), 25 | print("than or equal to", num) 26 | SieveOfEratosthenes(num) 27 | -------------------------------------------------------------------------------- /Sieve_of_Eratosthenes.py: -------------------------------------------------------------------------------- 1 | 2 | def SieveOfEratosthenes(num): 3 | prime = [True for i in range(num+1)] 4 | p = 2 5 | while (p * p <= num): 6 | 7 | if (prime[p] == True): 8 | 9 | for i in range(p * p, num+1, p): 10 | prime[i] = False 11 | p += 1 12 | 13 | for p in range(2, num+1): 14 | if prime[p]: 15 | print(p) 16 | 17 | if __name__ == '__main__': 18 | num = 50 19 | print("Following are the prime numbers smaller"), 20 | print("than or equal to", num) 21 | SieveOfEratosthenes(num) 22 | -------------------------------------------------------------------------------- /Speaking News App/Speaking News App.py: -------------------------------------------------------------------------------- 1 | from logging.config import listen 2 | import speech_recognition as sr 3 | import pyttsx3 4 | from GoogleNews import GoogleNews 5 | 6 | news = GoogleNews() 7 | a = pyttsx3.init() 8 | speak_voice = a.getProperty('voices') 9 | a.setProperty('voice',speak_voice[1].id) 10 | # voice of female put 1 for male put 0 11 | recognizer = sr.Recognizer() 12 | 13 | def speak_news(): 14 | with sr.Microphone() as source: 15 | print("Firstly clearing out the background noises ....") 16 | recognizer.adjust_for_ambient_noise(source, duration=1) 17 | print("Tell me the topic for which you want the news...") 18 | listen_voice = recognizer.listen(source, timeout=1) 19 | print("Your voice has been recorded") 20 | 21 | try: 22 | news_txt = recognizer.recognize_google(listen_voice,language='en_US') 23 | news_txt = news_txt.lower() 24 | print("You message which you said is : ",format(news_txt)) 25 | except Exception as e: 26 | print(e) 27 | 28 | if 'headlines' in news_txt: 29 | a.say("Wait Getting headlines of today for you") 30 | a.runAndWait() 31 | news.get_news('Today news') 32 | news.result() 33 | b = news.gettext() 34 | print(*b[1:5],sep=',') 35 | 36 | if 'sports' in news_txt: 37 | a.say("Wait Getting sports news of today for you") 38 | a.runAndWait() 39 | news.get_news('Sports') 40 | news.result() 41 | b = news.gettext() 42 | print(*b[1:5],sep=',') 43 | 44 | if 'tech' in news_txt: 45 | a.say("Wait Getting Technology news of today for you") 46 | a.runAndWait() 47 | news.get_news('Tech') 48 | news.result() 49 | b = news.gettext() 50 | print(*b[1:5],sep=',') 51 | 52 | speak_news() 53 | -------------------------------------------------------------------------------- /Spiral.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | from random import randint 3 | bgcolor('black') 4 | x = 1 5 | speed(0) 6 | while x < 400: 7 | 8 | r = randint(0,255) 9 | g = randint(0,255) 10 | b = randint(0,255) 11 | 12 | colormode(255) 13 | pencolor(r,g,b) 14 | fd(50 + x) 15 | rt(90.991) 16 | x = x+1 17 | 18 | exitonclick() 19 | -------------------------------------------------------------------------------- /StringPermutation.py: -------------------------------------------------------------------------------- 1 | def get_permutation(string, i=0): 2 | 3 | if i == len(string): 4 | print("".join(string)) 5 | 6 | for j in range(i, len(string)): 7 | 8 | words = [c for c in string] 9 | 10 | # swap 11 | words[i], words[j] = words[j], words[i] 12 | 13 | get_permutation(words, i + 1) 14 | 15 | print(get_permutation('yup')) 16 | -------------------------------------------------------------------------------- /Sudoku.py: -------------------------------------------------------------------------------- 1 | from pprint import pprint 2 | 3 | 4 | def find_next_empty(puzzle): 5 | for r in range(9): 6 | for c in range(9): 7 | if puzzle[r][c] == -1: 8 | return r, c 9 | 10 | return None, None 11 | 12 | def is_valid(puzzle, guess, row, col): 13 | row_vals = puzzle[row] 14 | if guess in row_vals: 15 | return False 16 | 17 | col_vals = [puzzle[i][col] for i in range(9)] 18 | if guess in col_vals: 19 | return False 20 | 21 | 22 | row_start = (row // 3) * 3 # 10 // 3 = 3, 5 // 3 = 1, 1 // 3 = 0 23 | col_start = (col // 3) * 3 24 | 25 | for r in range(row_start, row_start + 3): 26 | for c in range(col_start, col_start + 3): 27 | if puzzle[r][c] == guess: 28 | return False 29 | 30 | return True 31 | 32 | def solve_sudoku(puzzle): 33 | 34 | row, col = find_next_empty(puzzle) 35 | 36 | 37 | if row is None: 38 | return True 39 | 40 | 41 | for guess in range(1, 10): 42 | 43 | if is_valid(puzzle, guess, row, col): 44 | 45 | puzzle[row][col] = guess 46 | 47 | if solve_sudoku(puzzle): 48 | return True 49 | 50 | 51 | puzzle[row][col] = -1 52 | 53 | 54 | return False 55 | 56 | if __name__ == '__main__': 57 | example_board = [ 58 | [3, 9, -1, -1, 5, -1, -1, -1, -1], 59 | [-1, -1, -1, 2, -1, -1, -1, -1, 5], 60 | [-1, -1, -1, 7, 1, 9, -1, 8, -1], 61 | 62 | [-1, 5, -1, -1, 6, 8, -1, -1, -1], 63 | [2, -1, 6, -1, -1, 3, -1, -1, -1], 64 | [-1, -1, -1, -1, -1, -1, -1, -1, 4], 65 | 66 | [5, -1, -1, -1, -1, -1, -1, -1, -1], 67 | [6, 7, -1, 1, -1, 5, -1, 4, -1], 68 | [1, -1, 9, -1, -1, -1, 2, -1, -1] 69 | ] 70 | print(solve_sudoku(example_board)) 71 | pprint(example_board) 72 | -------------------------------------------------------------------------------- /Text to speech/Text to speech.py: -------------------------------------------------------------------------------- 1 | import pyttsx3 2 | book=open(r"#.txt") #insert file 3 | book_text=book.readlines() 4 | engine = pyttsx3.init() 5 | 6 | for i in book_text: 7 | engine.say(i) 8 | engine.runAndWait() 9 | -------------------------------------------------------------------------------- /Text_to_speech_convertor/Text_to_speech_convertor.py: -------------------------------------------------------------------------------- 1 | # Importing Libraries 2 | from logging import root 3 | from tkinter import * 4 | from gtts import gTTS 5 | from playsound import playsound 6 | 7 | # Initializing Window metrics 8 | root = Tk() 9 | root.geometry('400x350') 10 | root.configure(bg='white') 11 | root.title("TC's Text-to-Speech") 12 | 13 | Label(root, text="TEXT_TO_SPEECH", font="arial 30 bold", bg='white smoke').pack() 14 | Label(text="Text-to-Speech", font='arial 20 bold', 15 | bg='white smoke', width='20').pack(side='bottom') 16 | 17 | Txt = StringVar() 18 | Label(root, text="Enter Text", font='arial 20 bold', 19 | bg='white smoke').place(x=20, y=60) 20 | 21 | entry_field = Entry(root, textvariable='Txt', width='50') 22 | entry_field.place(x=20, y=100) 23 | 24 | 25 | # # TTS function 26 | # def Text_to_Speech(): 27 | # Msg = entry_field.get() 28 | # print(type(Msg)) 29 | # speech = gTTS(text=str(Message)) 30 | # speech.save('Textaudio.mp3') 31 | # playsound('Textaudio.mp3') 32 | 33 | 34 | # # Exit 35 | # def Exit(): 36 | # root.destroy() 37 | 38 | 39 | # # Reset 40 | # def reset(): 41 | # Txt.set("") 42 | 43 | 44 | # # Defining Buttons 45 | # Button(root, text="PLAY", font='arial 20 bold', 46 | # command=Text_to_Speech, width='4').place(x=25, y=140) 47 | # Button(root, font='arial 20 bold', text='EXIT', width='4', 48 | # command=Exit, bg='OrangeRed1').place(x=100, y=140) 49 | # Button(root, font='arial 20 bold', text='RESET', 50 | # width='6', command=reset).place(x=175, y=140) 51 | 52 | # root.mainloop() -------------------------------------------------------------------------------- /Tic Tac Toe Game/tic_tac_toe.py: -------------------------------------------------------------------------------- 1 | # Tic-Tac-Toe Program using 2 | # random number in Python 3 | 4 | # import libraries 5 | import numpy as np 6 | import random 7 | from time import sleep 8 | 9 | # Creates an empty board 10 | def create_board(): 11 | return(np.array([[0, 0, 0], 12 | [0, 0, 0], 13 | [0, 0, 0]])) 14 | 15 | # Check for empty places on board 16 | def possibilities(board): 17 | l = [] 18 | 19 | for i in range(len(board)): 20 | for j in range(len(board)): 21 | 22 | if board[i][j] == 0: 23 | l.append((i, j)) 24 | return(l) 25 | 26 | # Select a random place for the player 27 | def random_place(board, player): 28 | selection = possibilities(board) 29 | current_loc = random.choice(selection) 30 | board[current_loc] = player 31 | return(board) 32 | 33 | # Checks whether the player has three 34 | # of their marks in a horizontal row 35 | def row_win(board, player): 36 | for x in range(len(board)): 37 | win = True 38 | 39 | for y in range(len(board)): 40 | if board[x, y] != player: 41 | win = False 42 | continue 43 | 44 | if win == True: 45 | return(win) 46 | return(win) 47 | 48 | # Checks whether the player has three 49 | # of their marks in a vertical row 50 | def col_win(board, player): 51 | for x in range(len(board)): 52 | win = True 53 | 54 | for y in range(len(board)): 55 | if board[y][x] != player: 56 | win = False 57 | continue 58 | 59 | if win == True: 60 | return(win) 61 | return(win) 62 | 63 | # Checks whether the player has three 64 | # of their marks in a diagonal row 65 | def diag_win(board, player): 66 | win = True 67 | y = 0 68 | for x in range(len(board)): 69 | if board[x, x] != player: 70 | win = False 71 | if win: 72 | return win 73 | win = True 74 | if win: 75 | for x in range(len(board)): 76 | y = len(board) - 1 - x 77 | if board[x, y] != player: 78 | win = False 79 | return win 80 | 81 | # Evaluates whether there is 82 | # a winner or a tie 83 | def evaluate(board): 84 | winner = 0 85 | 86 | for player in [1, 2]: 87 | if (row_win(board, player) or 88 | col_win(board,player) or 89 | diag_win(board,player)): 90 | 91 | winner = player 92 | 93 | if np.all(board != 0) and winner == 0: 94 | winner = -1 95 | return winner 96 | 97 | # Main function to start the game 98 | def play_game(): 99 | board, winner, counter = create_board(), 0, 1 100 | print(board) 101 | sleep(2) 102 | 103 | while winner == 0: 104 | for player in [1, 2]: 105 | board = random_place(board, player) 106 | print("Board after " + str(counter) + " move") 107 | print(board) 108 | sleep(2) 109 | counter += 1 110 | winner = evaluate(board) 111 | if winner != 0: 112 | break 113 | return(winner) 114 | 115 | # Driver Code 116 | print("Winner is: " + str(play_game())) 117 | -------------------------------------------------------------------------------- /Tic_tac_toe.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | import random 4 | from time import sleep 5 | 6 | 7 | def create_board(): 8 | return(np.array([[0, 0, 0], 9 | [0, 0, 0], 10 | [0, 0, 0]])) 11 | 12 | 13 | def possibilities(board): 14 | l = [] 15 | 16 | for i in range(len(board)): 17 | for j in range(len(board)): 18 | 19 | if board[i][j] == 0: 20 | l.append((i, j)) 21 | return(l) 22 | 23 | 24 | def random_place(board, player): 25 | selection = possibilities(board) 26 | current_loc = random.choice(selection) 27 | board[current_loc] = player 28 | return(board) 29 | 30 | 31 | def row_win(board, player): 32 | for x in range(len(board)): 33 | win = True 34 | 35 | for y in range(len(board)): 36 | if board[x, y] != player: 37 | win = False 38 | continue 39 | 40 | if win == True: 41 | return(win) 42 | return(win) 43 | 44 | 45 | def col_win(board, player): 46 | for x in range(len(board)): 47 | win = True 48 | 49 | for y in range(len(board)): 50 | if board[y][x] != player: 51 | win = False 52 | continue 53 | 54 | if win == True: 55 | return(win) 56 | return(win) 57 | 58 | 59 | def diag_win(board, player): 60 | win = True 61 | y = 0 62 | for x in range(len(board)): 63 | if board[x, x] != player: 64 | win = False 65 | if win: 66 | return win 67 | win = True 68 | if win: 69 | for x in range(len(board)): 70 | y = len(board) - 1 - x 71 | if board[x, y] != player: 72 | win = False 73 | return win 74 | 75 | 76 | def evaluate(board): 77 | winner = 0 78 | 79 | for player in [1, 2]: 80 | if (row_win(board, player) or 81 | col_win(board,player) or 82 | diag_win(board,player)): 83 | 84 | winner = player 85 | 86 | if np.all(board != 0) and winner == 0: 87 | winner = -1 88 | return winner 89 | 90 | 91 | def play_game(): 92 | board, winner, counter = create_board(), 0, 1 93 | print(board) 94 | sleep(2) 95 | 96 | while winner == 0: 97 | for player in [1, 2]: 98 | board = random_place(board, player) 99 | print("Board after " + str(counter) + " move") 100 | print(board) 101 | sleep(2) 102 | counter += 1 103 | winner = evaluate(board) 104 | if winner != 0: 105 | break 106 | return(winner) 107 | 108 | 109 | print("Winner is: " + str(play_game())) 110 | -------------------------------------------------------------------------------- /Timer/Timer.py: -------------------------------------------------------------------------------- 1 | # Create a timer 2 | 3 | from time import sleep 4 | 5 | def setTimer(target_duration: int): 6 | """ 7 | A simple timer function. 8 | """ 9 | 10 | current_duration = 0 11 | 12 | while current_duration < target_duration: 13 | print(current_duration, end="\r") 14 | 15 | sleep(1) 16 | 17 | current_duration += 1 18 | 19 | print("Your time is up!") 20 | 21 | target_duration = int(input("Enter the duration in seconds: ")) 22 | 23 | setTimer(target_duration) 24 | -------------------------------------------------------------------------------- /To_check_prime_number.py: -------------------------------------------------------------------------------- 1 | num = 29 2 | 3 | # To take input from the user 4 | #num = int(input("Enter a number: ")) 5 | 6 | # define a flag variable 7 | flag = False 8 | 9 | # prime numbers are greater than 1 10 | if num > 1: 11 | # check for factors 12 | for i in range(2, num): 13 | if (num % i) == 0: 14 | # if factor is found, set flag to True 15 | flag = True 16 | # break out of loop 17 | break 18 | 19 | # check if flag is True 20 | if flag: 21 | print(num, "is not a prime number") 22 | else: 23 | print(num, "is a prime number") 24 | -------------------------------------------------------------------------------- /Travelling Salesman Problem/tsp_nn.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Python implementation for the Nearest Neighbours Heuristic for the Travelling Salesman Problem, visualized using Python Turtle. 3 | Author: D1Dayer99 4 | ''' 5 | 6 | import turtle 7 | import random 8 | import math 9 | 10 | t = turtle.Turtle() 11 | # turtle.tracer(100) 12 | t.speed(100) 13 | 14 | ''' 15 | Algorithm Description: 16 | Greedy algorithm 17 | 1 . Randomly select point as the root. 18 | 2. Find the point that is closest to the current position but is not yet part of the route, and add it into the route. 19 | 3. Repeat until the route includes each vertex. 20 | ''' 21 | 22 | 23 | class TSP_NN: 24 | 25 | def __init__(self): 26 | self.points = self.gen_points() 27 | self.destinations = self.get_destinations() 28 | self.connect_points() 29 | 30 | def gen_points(self): 31 | ''' 32 | Generating n (50) cooredinates within the specified range, the range is set to -300 < x < 300 33 | Visualizing each point using Python Turtle 34 | ''' 35 | self.pts = [((random.randint(-300, 300)), random.randint(-300, 300)) 36 | for i in range(50)] 37 | for coords in self.pts: 38 | t.penup() 39 | t.goto(coords[0], coords[1]) 40 | t.pendown() 41 | t.dot(10) 42 | t.write(coords) 43 | print(self.pts) 44 | t.penup() 45 | 46 | def get_destinations(self) -> list: 47 | ''' 48 | Starting with one point, the distance between every points are culculated using Pythagoreas' Theorem and is compared to previous values. 49 | The nearest point is then added to the list of destinations 50 | ''' 51 | self.start_point = self.pts[0] 52 | destinations = [] 53 | min_distance = 123467897383 54 | current_point = self.start_point 55 | self.pts.remove(current_point) 56 | while len(self.pts) != 0: 57 | for coords in self.pts: 58 | a = coords[0] - current_point[0] 59 | b = coords[1] - current_point[1] 60 | c = math.sqrt((a**2)+(b**2)) 61 | if c < min_distance: 62 | min_distance = c 63 | x_coord, y_coord = coords 64 | destinations.append((x_coord, y_coord)) 65 | current_point = (x_coord, y_coord) 66 | min_distance = 34567898765 67 | self.pts.remove(current_point) 68 | 69 | return destinations 70 | 71 | def connect_points(self): 72 | ''' 73 | For every destination, draw a line to it. Once all popints are visited, return back to the starting point 74 | ''' 75 | t.penup() 76 | t.goto(self.start_point) 77 | for i in range(len(self.destinations)): 78 | t.pendown() 79 | t.goto(self.destinations[i][0], self.destinations[i][1]) 80 | t.goto(self.start_point) 81 | 82 | 83 | tsp1 = TSP_NN() 84 | turtle.done() 85 | -------------------------------------------------------------------------------- /Tushar Nain/BinarySearch.py: -------------------------------------------------------------------------------- 1 | def binary_search(arr, x): 2 | low = 0 3 | high = len(arr) - 1 4 | mid = 0 5 | 6 | while low <= high: 7 | 8 | mid = (high + low) // 2 9 | 10 | if arr[mid] < x: 11 | low = mid + 1 12 | 13 | elif arr[mid] > x: 14 | high = mid - 1 15 | 16 | else: 17 | return mid 18 | 19 | return -1 20 | 21 | #example array 22 | arr = [ 2, 3, 4, 10, 40 ] 23 | x = 10 24 | 25 | result = binary_search(arr, x) 26 | 27 | if result != -1: 28 | print("Element is present at index", str(result)) 29 | else: 30 | print("Element is not present in array") -------------------------------------------------------------------------------- /Varad Chandrawar/Additionoftwomatrix.py: -------------------------------------------------------------------------------- 1 | for i in range(len(X)): 2 | # iterate through columns 3 | for j in range(len(X[0])): 4 | result[i][j] = X[i][j] + Y[i][j] 5 | 6 | for r in result: 7 | print(r) -------------------------------------------------------------------------------- /Varad Chandrawar/LCM.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/Varad Chandrawar/LCM.py -------------------------------------------------------------------------------- /Varun Kotgire/Prime.py: -------------------------------------------------------------------------------- 1 | # Program to check if a number is prime or not 2 | 3 | num = 407 4 | 5 | # To take input from the user 6 | #num = int(input("Enter a number: ")) 7 | 8 | # prime numbers are greater than 1 9 | if num > 1: 10 | # check for factors 11 | for i in range(2,num): 12 | if (num % i) == 0: 13 | print(num,"is not a prime number") 14 | print(i,"times",num//i,"is",num) 15 | break 16 | else: 17 | print(num,"is a prime number") 18 | 19 | # if input number is less than 20 | # or equal to 1, it is not prime 21 | else: 22 | print(num,"is not a prime number") -------------------------------------------------------------------------------- /Web_Scrapping.py: -------------------------------------------------------------------------------- 1 | #Requirements 2 | #pip3 install requests 3 | #pip3 install bs4 4 | 5 | #run in the browser also what are you doing with the help of chrome driver 6 | from bs4 import BeautifulSoup 7 | import requests 8 | from selenium import webdriver 9 | url="https://getpython.wordpress.com/" 10 | BASE_URL = "https://getpython.wordpress.com/" 11 | source=requests.get(url) 12 | 13 | 14 | def get_chrome_web_driver(options): 15 | return webdriver.Chrome("./chromedriver", chrome_options=options) 16 | 17 | 18 | def get_web_driver_options(): 19 | return webdriver.ChromeOptions() 20 | 21 | 22 | def set_ignore_certificate_error(options): 23 | options.add_argument('--ignore-certificate-errors') 24 | 25 | 26 | def set_browser_as_incognito(options): 27 | options.add_argument('--incognito') 28 | soup=BeautifulSoup(source.text,'html') 29 | title=soup.find('title') 30 | print("this is with html tags :",title) 31 | 32 | qwery=soup.find('h1') 33 | print("this is without html tags:",qwery.text) 34 | 35 | 36 | links=soup.find('a') 37 | print(links) 38 | print(links['href']) 39 | for a in soup.find_all('a', href=True): 40 | print ( a['href']) 41 | 42 | for i in links: 43 | print(i.text) 44 | print(links['class']) 45 | 46 | many_link=soup.find_all('a') 47 | total_links=len(many_link) 48 | print("total links in my website :",total_links) 49 | print() 50 | for i in many_link[:6]: 51 | print(i) 52 | 53 | second_link=many_link[1] 54 | print(second_link) 55 | print() 56 | print("href is :",second_link['href']) 57 | 58 | 59 | 60 | nested_div=second_link.find('div') 61 | print(nested_div) 62 | print() 63 | z=(nested_div['class']) 64 | print(z) 65 | print(type(z)) 66 | print() 67 | print("class name of div is :"," ".join(nested_div['class'])) 68 | 69 | 70 | wiki=requests.get("https://en.wikipedia.org/wiki/World_War_II") 71 | soup=BeautifulSoup(wiki.text,'html') 72 | print(soup.find('title')) 73 | 74 | 75 | ww2_contents=soup.find_all("div",class_='toc') 76 | for i in ww2_contents: 77 | print(i.text) 78 | 79 | 80 | overview=soup.find_all('table',class_='infobox vevent') 81 | for z in overview: 82 | print(z.text) 83 | 84 | images=soup.find_all('img') 85 | 86 | images 87 | print(images) 88 | -------------------------------------------------------------------------------- /Youtube_video_downloader/Youtube_video_downloader.py: -------------------------------------------------------------------------------- 1 | # importing module 2 | import youtube_dl 3 | from bs4 import BeautifulSoup 4 | import requests 5 | from tkinter import * 6 | import tkinter.ttk as ttk 7 | 8 | 9 | # defining functions 10 | 11 | # function to download the video 12 | def downloadvideo(): 13 | link_of_the_video = video_link_entry.get() 14 | link = link_of_the_video.strip() 15 | ydl_opts = { 16 | 'outtmpl': r"C:/Users/rsrs/YouTube/%(title)s.%(ext)s", 17 | 'progress_hooks': [my_hook], 18 | } 19 | with youtube_dl.YoutubeDL(ydl_opts) as ydl: 20 | ydl.download([link]) 21 | # getting the title of the video 22 | req = requests.get(link) 23 | s = BeautifulSoup(req.text, "html.parser") 24 | title = s.find("title") 25 | title_2 = title.string.replace("", " ") 26 | title_3 = title_2.replace(" - YouTube", "") 27 | video_title = Label(gui, text="Video Title: " + title_3, font="arial 8 bold", foreground="Black", 28 | background="light cyan") 29 | video_title.place(x=100, y=160) 30 | 31 | 32 | # print("Title: ",title_3) 33 | # print("File location: ",r"C:\Users\rsrs\YouTube") 34 | 35 | # function called after the video is downloaded to change the labels 36 | def after_download_msg(): 37 | video_link.destroy() 38 | video_link_entry.destroy() 39 | button1.destroy() 40 | download_msg.place(x=100, y=100) 41 | path_msg.place(x=100, y=130) 42 | 43 | 44 | # my_hook determines the progress of the download 45 | def my_hook(d): 46 | if d['status'] == 'finished': 47 | after_download_msg() 48 | print("Done downloading") 49 | if d['status'] == 'downloading': 50 | gui.update_idletasks() 51 | pb1['value'] = float(str(d['_percent_str']).replace("%", "")) 52 | # print(d['filename'], d['_percent_str'], d['_eta_str']) 53 | 54 | 55 | # main code 56 | 57 | # creating gui window 58 | gui = Tk() 59 | gui.geometry("500x500") 60 | gui.config(background="PeachPuff2") 61 | gui.resizable(width=True, height=True) 62 | gui.title('YouTube Video Downloader') 63 | # making labels, entry box and button 64 | video_link = Label(gui, text="Copy & paste the URL of the YouTube video you want to download:- ", font="arial 8 bold", foreground="Black", background="floral white") 65 | video_link.place(x=60, y=50) 66 | video_link_entry = Entry(gui, background="SkyBlue2", width=62) 67 | video_link_entry.place(x=60, y=100) 68 | button1 = Button(gui, text="Enter", bg="white", command=lambda: downloadvideo(), height=1, width=7, relief=GROOVE) 69 | button1.place(x=195, y=150) 70 | download_msg = Label(gui, text="Your video has been downloaded and is in the folder", font="arial 8 bold", foreground="Black", background="light cyan") 71 | path_msg = Label(gui, text=r"C:\Users\rsrs\YouTube", font="arial 8 bold", foreground="Black", background="light cyan") 72 | # making the progress bar which takes the progress updates from the my_hook function 73 | pb1 = ttk.Progressbar(gui, orient=HORIZONTAL, length=300, mode='indeterminate') 74 | pb1.grid(padx=100, pady=200) 75 | 76 | gui.mainloop() 77 | -------------------------------------------------------------------------------- /alarm_clock.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from playsound import playsound 3 | alarm_time = input("Enter the time of alarm to be set:HH:MM:SS\n") 4 | alarm_hour=alarm_time[0:2] 5 | alarm_minute=alarm_time[3:5] 6 | alarm_seconds=alarm_time[6:8] 7 | alarm_period = alarm_time[9:11].upper() 8 | print("Setting up alarm..") 9 | while True: 10 | now = datetime.now() 11 | current_hour = now.strftime("%I") 12 | current_minute = now.strftime("%M") 13 | current_seconds = now.strftime("%S") 14 | current_period = now.strftime("%p") 15 | if(alarm_period==current_period): 16 | if(alarm_hour==current_hour): 17 | if(alarm_minute==current_minute): 18 | if(alarm_seconds==current_seconds): 19 | print("Wake Up!") 20 | playsound('audio.mp3') 21 | break 22 | -------------------------------------------------------------------------------- /athul/.largest.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/athul/.largest.py -------------------------------------------------------------------------------- /athul/largest.py: -------------------------------------------------------------------------------- 1 | 2 | num1 = 25 3 | num2 = 30 4 | num3 = 20 5 | 6 | 7 | 8 | if (num1 >= num2) and (num1 >= num3): 9 | largest = num1 10 | elif (num2 >= num1) and (num2 >= num3): 11 | largest = num2 12 | else: 13 | largest = num3 14 | 15 | 16 | print("The largest number is", largest) 17 | -------------------------------------------------------------------------------- /attendance.txt: -------------------------------------------------------------------------------- 1 | <html> 2 | <head> 3 | <title>Login form Design 4 | 5 |
6 | 7 | Login Here 8 |
9 |

Username

10 | 11 |

Password

12 | 13 | 14 | Lost your password?
15 | Don't have an account?
16 |
17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /auto_clicker using automation/auto_clicker.py: -------------------------------------------------------------------------------- 1 | import pyautogui 2 | from pynput.keyboard import Key, Listener 3 | 4 | # ======== Controls ======== 5 | start_or_pause_key = Key.f1 6 | exit_key = Key.esc 7 | delay = 1 # seconds 8 | 9 | # ==== global variables ==== 10 | pause = True 11 | running = True 12 | 13 | 14 | def display_controls(): 15 | 16 | print("F1 = Start / Pause") 17 | print("ESC = Exit\n") 18 | 19 | 20 | def choose_delay(): 21 | 22 | try: 23 | return float(input("Enter wanted delay (seconds): ")) 24 | except ValueError: 25 | print(f"You did not give a valid input, default delay : {delay}sec") 26 | return delay 27 | 28 | 29 | def key_press(key): 30 | global running, pause 31 | 32 | if key == start_or_pause_key: 33 | pause = not pause 34 | print("< Pause >") if pause else print("< Start >") 35 | elif key == exit_key: 36 | running = False 37 | print("< Exit >") 38 | 39 | 40 | def main(): 41 | 42 | delay = choose_delay() 43 | print(f"delay = {str(delay)}sec\n") 44 | display_controls() 45 | 46 | listener = Listener(on_press=key_press) 47 | listener.start() 48 | 49 | while running: 50 | if not pause: 51 | pyautogui.click(pyautogui.position()) 52 | pyautogui.PAUSE = delay 53 | listener.stop() 54 | 55 | 56 | if __name__ == "__main__": 57 | main() -------------------------------------------------------------------------------- /auto_clicker using automation/readme.md: -------------------------------------------------------------------------------- 1 | # AutoClicker 2 | This is a basic autoclicker, you can choose the delay you want between each click. 3 | ## Prerequisites 4 | 5 | **Python 3.8.x** 6 | 7 | ## Setup and activate virtual environment : 8 | For Unix based systems please execute the following command to create venv and install requirements. 9 | ``` 10 | make init 11 | source .venv/bin/activate 12 | ``` 13 | 14 | Then you can run the script! 15 | 16 | ## Controls 17 | Key | Action 18 | --- | --- 19 | F1 | Resume / Pause 20 | ESC | Exit the program -------------------------------------------------------------------------------- /binary_search.py: -------------------------------------------------------------------------------- 1 | # Iterative Binary Search Function method Python Implementation 2 | # It returns index of n in given list1 if present, 3 | # else returns -1 4 | def binary_search(list1, n): 5 | low = 0 6 | high = len(list1) - 1 7 | mid = 0 8 | 9 | while low <= high: 10 | # for get integer result 11 | mid = (high + low) // 2 12 | 13 | # Check if n is present at mid 14 | if list1[mid] < n: 15 | low = mid + 1 16 | 17 | # If n is greater, compare to the right of mid 18 | elif list1[mid] > n: 19 | high = mid - 1 20 | 21 | # If n is smaller, compared to the left of mid 22 | else: 23 | return mid 24 | 25 | # element was not present in the list, return -1 26 | return -1 27 | 28 | 29 | # Initial list1 30 | list1 = [12, 24, 32, 39, 45, 50, 54] 31 | n = 45 32 | 33 | # Function call 34 | result = binary_search(list1, n) 35 | 36 | if result != -1: 37 | print("Element is present at index", str(result)) 38 | else: 39 | print("Element is not present in list1") 40 | -------------------------------------------------------------------------------- /bubble_sort.py: -------------------------------------------------------------------------------- 1 | # Creating a bubble sort function 2 | def bubble_sort(list1): 3 | # Outer loop for traverse the entire list 4 | for i in range(0,len(list1)-1): 5 | for j in range(len(list1)-1): 6 | if(list1[j]>list1[j+1]): 7 | temp = list1[j] 8 | list1[j] = list1[j+1] 9 | list1[j+1] = temp 10 | return list1 11 | 12 | list1 = [5, 3, 8, 6, 7, 2] 13 | print("The unsorted list is: ", list1) 14 | # Calling the bubble sort function 15 | print("The sorted list is: ", bubble_sort(list1)) 16 | -------------------------------------------------------------------------------- /bubblesort/bubblesort.py: -------------------------------------------------------------------------------- 1 | # Python3 program for Bubble Sort Algorithm Implementation 2 | def bubbleSort(arr): 3 | 4 | n = len(arr) 5 | 6 | # For loop to traverse through all 7 | # element in an array 8 | for i in range(n): 9 | for j in range(0, n - i - 1): 10 | 11 | # Range of the array is from 0 to n-i-1 12 | # Swap the elements if the element found 13 | #is greater than the adjacent element 14 | if arr[j] > arr[j + 1]: 15 | arr[j], arr[j + 1] = arr[j + 1], arr[j] 16 | 17 | # Driver code 18 | 19 | # Example to test the above code 20 | arr = [ 2, 1, 10, 23 ] 21 | 22 | bubbleSort(arr) 23 | 24 | print("Sorted array is:") 25 | for i in range(len(arr)): 26 | print("%d" % arr[i]) 27 | -------------------------------------------------------------------------------- /caesar_cipher.py: -------------------------------------------------------------------------------- 1 | k = [chr(ord("A")+i) for i in range(26)] 2 | v = [i for i in range(26)] 3 | d = {k[i] : v[i] for i in range(26)} 4 | 5 | def get_key(val): 6 | for key,value in d.items(): 7 | if(value == val): 8 | return key 9 | 10 | def encrypt(pt): 11 | key = 7 12 | li = [] 13 | for i in pt: 14 | li.append((d[i] + key)%26) 15 | 16 | for i in range(len(li)): 17 | li[i] = get_key(li[i]) 18 | 19 | # print(li) 20 | 21 | st = "" 22 | for i in li: 23 | st += i 24 | # print(st) 25 | return st 26 | 27 | def decrypt(pt): 28 | st = "" 29 | for i in range(len(pt)): 30 | a = d[pt[i]] - 7 31 | if(a < 0): 32 | a += 26 33 | st += get_key(a) 34 | # print(st) 35 | return st 36 | 37 | pt = input("Enter plain text(Don't Add Space): ") 38 | pt = pt.upper() 39 | a = encrypt(pt) 40 | print("Encrypted Message:",a) 41 | print("Decrypted Message:",decrypt(a)) -------------------------------------------------------------------------------- /calculator.py: -------------------------------------------------------------------------------- 1 | 2 | def add(x, y): 3 | return x + y 4 | 5 | # This function subtracts two numbers 6 | def subtract(x, y): 7 | return x - y 8 | 9 | # This function multiplies two numbers 10 | def multiply(x, y): 11 | return x * y 12 | 13 | # This function divides two numbers 14 | def divide(x, y): 15 | return x / y 16 | 17 | 18 | print("Select operation.") 19 | print("1.Add") 20 | print("2.Subtract") 21 | print("3.Multiply") 22 | print("4.Divide") 23 | 24 | while True: 25 | 26 | choice = input("Enter choice(1/2/3/4): ") 27 | 28 | 29 | if choice in ('1', '2', '3', '4'): 30 | num1 = float(input("Enter first number: ")) 31 | num2 = float(input("Enter second number: ")) 32 | 33 | if choice == '1': 34 | print(num1, "+", num2, "=", add(num1, num2)) 35 | 36 | elif choice == '2': 37 | print(num1, "-", num2, "=", subtract(num1, num2)) 38 | 39 | elif choice == '3': 40 | print(num1, "*", num2, "=", multiply(num1, num2)) 41 | 42 | elif choice == '4': 43 | print(num1, "/", num2, "=", divide(num1, num2)) 44 | 45 | 46 | next_calculation = input("Let's do next calculation? (yes/no): ") 47 | if next_calculation == "no": 48 | break 49 | 50 | else: 51 | print("Invalid Input") 52 | -------------------------------------------------------------------------------- /chat_bot/Readme.md: -------------------------------------------------------------------------------- 1 | # Simple ChatBot 2 | 3 | Simple rule based **ChatBot**. A rule-based chatbot uses a tree-like flow instead of AI to help guests with their queries. This means that the chatbot will guide the guest with follow-up questions to eventually get to the correct resolution. The structures and answers are all pre-defined so that you are in control of the conversation. 4 | Python requirements 5 | 6 | # Python 3.0 or newer 7 | 8 | Modules 9 | re package - It handles regular expression in Python. WordNet from NLTK - WordNet is a lexical database that defines semantical relationships between words. -------------------------------------------------------------------------------- /chat_bot/chat_bot.py: -------------------------------------------------------------------------------- 1 | from nltk.chat.util import Chat, reflections 2 | 3 | Set_pairs = [ 4 | [ 5 | r"my name is (.*)", 6 | ["Hello %l, How are you today?", ] 7 | ], 8 | [ 9 | r"hi|hey|hello", 10 | ["Hello", "Hey there", ] 11 | ], 12 | [ 13 | r"(.*)help(.*) ", 14 | ["I can help you ", ] 15 | ], 16 | [ 17 | r"(.*) your name ?", 18 | ["My name is beedo, but you can just call me robot & I'm a chatbot.", ] 19 | ], 20 | [ 21 | r"how are you (.*) ?", 22 | ["I'm doing very well", "i am great !", ] 23 | ], 24 | [ 25 | r"sorry (.*)", 26 | ["Its alright", "Its OK, never mind that", ] 27 | ], 28 | [ 29 | r"i'm (.*) (good|well|okay|ok)", 30 | ["Nice to hear that", "Alright, great !", ] 31 | ], 32 | [ 33 | r"(hi|hey|hello|hola|holla)(.*)", 34 | ["Hello", "Hey there", ] 35 | ], 36 | [ 37 | r"what (.*) want ?", 38 | ["Make me an offer I can't refuse", ] 39 | ], 40 | [ 41 | r"(.*)created(.*)", 42 | ["XYZ created me using Python's NLTK library ", "top secret ;)", ] 43 | ], 44 | [ 45 | r"(.*) (location|city) ?", 46 | ['New Delhi, India', ] 47 | ], 48 | [ 49 | r"(.*)raining in (.*)", 50 | ["No rain in the past 4 days here in %2", ] 51 | ], 52 | [ 53 | r"how (.*) health (.*)", 54 | ["I am a computer, so I don't need to worry about my health ", ] 55 | ], 56 | [ 57 | r"(.*)(sports|game|sport)(.*)", 58 | ["I'm a very big fan of Cricket", ] 59 | ], 60 | [ 61 | r"who (.*) (Cricketer|Batsman)?", 62 | ["Virat Kohli", ] 63 | ], 64 | [ 65 | r"quit", 66 | ["Bye for now. See you soon :) ", "It was nice talking to you.", ] 67 | ], 68 | [ 69 | r"(.*)", 70 | ['That is nice to hear'] 71 | ], 72 | ] 73 | 74 | 75 | def chatbot(): 76 | print("Hi I am a rule-based chatbot ! what can i help you with?") 77 | 78 | 79 | chatbot() 80 | 81 | 82 | chat = Chat(Set_pairs, reflections) 83 | print(chat) 84 | 85 | chat.converse() 86 | if __name__ == "__main__": 87 | chatbot() -------------------------------------------------------------------------------- /check_palindrome_symmetric.py: -------------------------------------------------------------------------------- 1 | def check(s): 2 | s1=s[::-1] 3 | if(s==s1): 4 | print("The given string is palindrome") 5 | else: 6 | print("The given string is not palindrome") 7 | m=s[0:len(s)//2] 8 | n=s[len(s)//2::] 9 | if(m==n): 10 | print("The given string is Symmetric") 11 | else: 12 | print("The given string is not symmetric") 13 | s=input("Enter the string:") 14 | check(s) 15 | -------------------------------------------------------------------------------- /clock/clock.py: -------------------------------------------------------------------------------- 1 | import time 2 | from tkinter import * 3 | 4 | root=Tk() 5 | root.geometry("359x150+0+0") 6 | root.configure(background="black") 7 | root.resizable(0,0) 8 | 9 | 10 | 11 | root.overrideredirect(1) 12 | 13 | 14 | def clock(): 15 | curr_time=time.strftime("%H:%M:%S") 16 | label.config(text=curr_time) 17 | label.after(200,clock) 18 | 19 | 20 | label = Label(root,font=("ds-DIGITAL",50,"bold"),bg='black',fg='white',bd=50) 21 | label.grid(row=0,column=1) 22 | 23 | 24 | clock() 25 | 26 | 27 | print("Done") 28 | root.mainloop() -------------------------------------------------------------------------------- /comment.py: -------------------------------------------------------------------------------- 1 | example of single one comment : 2 | #this is an example of single line comment. 3 | 4 | example of multiple line comment : 5 | 6 | ''' this 7 | is the example 8 | for multiple lines comment 9 | in python''' 10 | 11 | or 12 | 13 | """this 14 | is the example 15 | for multiple lines comment 16 | in python""" 17 | 18 | -------------------------------------------------------------------------------- /count no. of One bits: -------------------------------------------------------------------------------- 1 | def get_set_bits_count(number: int) -> int: 2 | """ 3 | Count the number of set bits in a 32 bit integer 4 | >>> get_set_bits_count(25) 5 | 3 6 | >>> get_set_bits_count(37) 7 | 3 8 | >>> get_set_bits_count(21) 9 | 3 10 | >>> get_set_bits_count(58) 11 | 4 12 | >>> get_set_bits_count(0) 13 | 0 14 | >>> get_set_bits_count(256) 15 | 1 16 | >>> get_set_bits_count(-1) 17 | Traceback (most recent call last): 18 | ... 19 | ValueError: the value of input must be positive 20 | """ 21 | if number < 0: 22 | raise ValueError("the value of input must be positive") 23 | result = 0 24 | while number: 25 | if number % 2 == 1: 26 | result += 1 27 | number = number >> 1 28 | return result 29 | 30 | 31 | if __name__ == "__main__": 32 | import doctest 33 | 34 | doctest.testmod() 35 | -------------------------------------------------------------------------------- /dav/program.py: -------------------------------------------------------------------------------- 1 | # Python3 Program to find 2 | # transpose of a matrix 3 | 4 | M = 3 5 | N = 4 6 | 7 | # This function stores 8 | # transpose of A[][] in B[][] 9 | 10 | def transpose(A, B): 11 | 12 | for i in range(N): 13 | for j in range(M): 14 | B[i][j] = A[j][i] 15 | 16 | # driver code 17 | A = [ [1, 1, 1, 1], 18 | [2, 2, 2, 2], 19 | [3, 3, 3, 3]] 20 | 21 | 22 | # To store result 23 | B = [[0 for x in range(M)] for y in range(N)] 24 | 25 | transpose(A, B) 26 | 27 | print("Result matrix is") 28 | for i in range(N): 29 | for j in range(M): 30 | print(B[i][j], " ", end='') 31 | print() 32 | -------------------------------------------------------------------------------- /divyansh99/divyansh99.cpp: -------------------------------------------------------------------------------- 1 | // CPP program to illustrate 2 | // Implementation of swap() function 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | // stack container declaration 10 | stack mystack1; 11 | stack mystack2; 12 | 13 | // pushing elements into first stack 14 | mystack1.push(1); 15 | mystack1.push(2); 16 | mystack1.push(3); 17 | mystack1.push(4); 18 | 19 | // pushing elements into 2nd stack 20 | mystack2.push(3); 21 | mystack2.push(5); 22 | mystack2.push(7); 23 | mystack2.push(9); 24 | 25 | // using swap() function to swap elements of stacks 26 | mystack1.swap(mystack2); 27 | 28 | // printing the first stack 29 | cout<<"mystack1 = "; 30 | while (!mystack1.empty()) { 31 | cout<= inp else root.key 19 | 20 | root = Node(8) 21 | 22 | root.left = Node(4) 23 | root.right = Node(12) 24 | 25 | root.left.left = Node(2) 26 | root.left.right = Node(6) 27 | 28 | root.right.left = Node(10) 29 | root.right.right = Node(14) 30 | 31 | for i in range(16): 32 | print "% d % d" %(i, ceil(root, i)) 33 | -------------------------------------------------------------------------------- /game.py: -------------------------------------------------------------------------------- 1 | import random 2 | choices = ["Rock", "Paper", "Scissors"] 3 | computer = random.choice(choices) 4 | player = False 5 | cpu_score = 0 6 | player_score = 0 7 | while True: 8 | player = input("Rock, Paper or Scissors?").capitalize() 9 | ## Conditions of Rock,Paper and Scissors 10 | if player == computer: 11 | print("Tie!") 12 | elif player == "Rock": 13 | if computer == "Paper": 14 | print("You lose!", computer, "covers", player) 15 | cpu_score+=1 16 | else: 17 | print("You win!", player, "smashes", computer) 18 | player_score+=1 19 | elif player == "Paper": 20 | if computer == "Scissors": 21 | print("You lose!", computer, "cut", player) 22 | cpu_score+=1 23 | else: 24 | print("You win!", player, "covers", computer) 25 | player_score+=1 26 | elif player == "Scissors": 27 | if computer == "Rock": 28 | print("You lose...", computer, "smashes", player) 29 | cpu_score+=1 30 | else: 31 | print("You win!", player, "cut", computer) 32 | player_score+=1 33 | elif player=='End': 34 | print("Final Scores:") 35 | print(f"CPU:{cpu_score}") 36 | print(f"Plaer:{player_score}") 37 | break 38 | -------------------------------------------------------------------------------- /garvit/garvit.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | num1 = 1.5 4 | num2 = 6.3 5 | 6 | # Add two numbers 7 | sum = num1 + num2 8 | 9 | # Display the sum 10 | print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) 11 | -------------------------------------------------------------------------------- /gaurav shah: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def countdown(time_sec): 4 | while time_sec: 5 | mins, secs = divmod(time_sec, 60) 6 | timeformat = '{:02d}:{:02d}'.format(mins, secs) 7 | print(timeformat, end='\r') 8 | time.sleep(1) 9 | time_sec -= 1 10 | 11 | print("stop") 12 | 13 | countdown(5) 14 | -------------------------------------------------------------------------------- /get Current Time/get Current Time.py: -------------------------------------------------------------------------------- 1 | from datetime import * 2 | import pytz 3 | 4 | 5 | tz_INDIA = pytz.timezone('Asia/Kolkata') 6 | datetime_INDIA = datetime.now(tz_INDIA) 7 | print("INDIA time:", datetime_INDIA.strftime("%H:%M:%S")) 8 | -------------------------------------------------------------------------------- /get_date.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | # using now() to get current time 4 | current_time = datetime.datetime.now() 5 | 6 | # Printing attributes of now(). 7 | print("The attributes of now() are :") 8 | 9 | print("Year :", current_time.year) 10 | 11 | print("Month : ", current_time.month) 12 | 13 | print("Day : ", current_time.day) 14 | 15 | print("Hour : ", current_time.hour) 16 | 17 | print("Minute : ", current_time.minute) 18 | 19 | print("Second :", current_time.second) 20 | 21 | print("Microsecond :", current_time.microsecond) 22 | -------------------------------------------------------------------------------- /greater_num.py: -------------------------------------------------------------------------------- 1 | 2 | num1 = 10 3 | num2 = 14 4 | num3 = 12 5 | 6 | 7 | #num1 = float(input("Enter first number: ")) 8 | #num2 = float(input("Enter second number: ")) 9 | #num3 = float(input("Enter third number: ")) 10 | 11 | if (num1 >= num2) and (num1 >= num3): 12 | largest = num1 13 | elif (num2 >= num1) and (num2 >= num3): 14 | largest = num2 15 | else: 16 | largest = num3 17 | 18 | print("The largest number is", largest) 19 | -------------------------------------------------------------------------------- /guess_num.py: -------------------------------------------------------------------------------- 1 | import random 2 | number = random.randint(1, 10) 3 | 4 | player_name = input("Hello, what is your name? ") 5 | number_of_guesses = 0 6 | print('I\'m glad to meet you! {} \nLet\'s play a game with you, I will think a number between 1 and 10 then you will guess, alright? \nDon\'t forget! You have only 3 chances so guess:'.format(player_name)) 7 | 8 | while number_of_guesses < 3: 9 | guess = int(input()) 10 | number_of_guesses += 1 11 | if guess < number: 12 | print('Your estimate is too low, go up a little!') 13 | if guess > number: 14 | print('Your estimate is too high, go down a bit!') 15 | if guess == number: 16 | break 17 | if guess == number: 18 | print( 'Congratulations {}, you guessed the number in {} tries!'.format(player_name, number_of_guesses)) 19 | else: 20 | print('Close but no cigar, you couldn\'t guess the number. \nWell, the number was {}.'.format(number)) 21 | -------------------------------------------------------------------------------- /hacktoberfest-quiz/hacktoberfest-quiz.py: -------------------------------------------------------------------------------- 1 | print('Welcome to the Hacktoberfest 2022 Quiz') 2 | answer=input('Are you ready to play the Quiz ? (yes/no) :') 3 | score=0 4 | total_questions=3 5 | 6 | if answer.lower()=='yes': 7 | answer=input('Question 1: What programming language was this created in?') 8 | if answer.lower()=='python': 9 | score += 1 10 | print('correct') 11 | else: 12 | print('Wrong Answer :(') 13 | 14 | 15 | answer=input('Question 2: Is one of the values of Hacktoberfest 2022 "EVERYONE IS WELCOME" ? ') 16 | if answer.lower()=='yes': 17 | score += 1 18 | print('correct') 19 | else: 20 | print('Wrong Answer :(') 21 | 22 | answer=input('Question 3: Does Hacktoberfest end on December 31?') 23 | if answer.lower()=='no': 24 | score += 1 25 | print('correct') 26 | else: 27 | print('Wrong Answer :(') 28 | 29 | print('Thankyou for Playing this small quiz game, you attempted',score,"questions correctly!") 30 | mark=(score/total_questions)*100 31 | print('Marks obtained:',mark) 32 | print('BYE!') 33 | -------------------------------------------------------------------------------- /hacktoberfest2022: -------------------------------------------------------------------------------- 1 | from tkinter import HIDDEN, NORMAL, Tk, Canvas 2 | def toggle_eyes(): 3 | current_color = c.itemcget(eye_left, 'fill') 4 | new_color = c.body_color if current_color == 'white' else 'white' 5 | current_state = c.itemcget(pupil_left, 'state') 6 | new_state = NORMAL if current_state == HIDDEN else HIDDEN 7 | c.itemconfigure(pupil_left, state=new_state) 8 | c.itemconfigure(pupil_right, state=new_state) 9 | c.itemconfigure(eye_left, fill=new_color) 10 | c.itemconfigure(eye_right, fill=new_color) 11 | 12 | def blink(): 13 | toggle_eyes() 14 | root.after(250, toggle_eyes) 15 | root.after(3000, blink) 16 | 17 | def toggle_pupils(): 18 | if not c.eyes_crossed: 19 | c.move(pupil_left, 10, -5) 20 | c.move(pupil_right, -10, -5) 21 | c.eyes_crossed = True 22 | else: 23 | c.move(pupil_left, -10, 5) 24 | c.move(pupil_right, 10, 5) 25 | c.eyes_crossed = False 26 | 27 | def toggle_tongue(): 28 | if not c.tongue_out: 29 | c.itemconfigure(tongue_tip, state=NORMAL) 30 | c.itemconfigure(tongue_main, state=NORMAL) 31 | c.tongue_out = True 32 | else: 33 | c.itemconfigure(tongue_tip, state=HIDDEN) 34 | c.itemconfigure(tongue_main, state=HIDDEN) 35 | c.tongue_out = False 36 | def cheeky(event): 37 | toggle_tongue() 38 | toggle_pupils() 39 | hide_happy(event) 40 | root.after(1000, toggle_tongue) 41 | root.after(1000, toggle_pupils) 42 | return 43 | 44 | def show_happy(event): 45 | if (20 <= event.x and event.x <= 350) and (20 <= event.y and event.y <= 350): 46 | c.itemconfigure(cheek_left, state=NORMAL) 47 | c.itemconfigure(cheek_right, state=NORMAL) 48 | c.itemconfigure(mouth_happy, state=NORMAL) 49 | c.itemconfigure(mouth_normal, state=HIDDEN) 50 | c.itemconfigure(mouth_sad, state=HIDDEN) 51 | c.happy_level = 10 52 | return 53 | 54 | def hide_happy(event): 55 | c.itemconfigure(cheek_left, state=HIDDEN) 56 | c.itemconfigure(cheek_right, state=HIDDEN) 57 | c.itemconfigure(mouth_happy, state=HIDDEN) 58 | c.itemconfigure(mouth_normal, state=NORMAL) 59 | c.itemconfigure(mouth_sad, state=HIDDEN) 60 | return 61 | 62 | def sad(): 63 | if c.happy_level == 0: 64 | c.itemconfigure(mouth_happy, state=HIDDEN) 65 | c.itemconfigure(mouth_normal, state=HIDDEN) 66 | c.itemconfigure(mouth_sad, state=NORMAL) 67 | else: 68 | c.happy_level -= 1 69 | root.after(5000, sad) 70 | 71 | root = Tk() 72 | root.title("Screen pet") 73 | c = Canvas(root, width=400, height=400) 74 | c.configure(bg='dark blue', highlightthickness=0) 75 | c.body_color = 'SkyBlue1' 76 | 77 | body = c.create_oval(35, 20, 365, 350, outline=c.body_color, fill=c.body_color) 78 | ear_left = c.create_polygon(75, 80, 75, 10, 165, 70, outline=c.body_color, fill=c.body_color) 79 | ear_right = c.create_polygon(255, 45, 325, 10, 320, 70, outline=c.body_color, fill=c.body_color) 80 | foot_left = c.create_oval(65, 320, 145, 360, outline=c.body_color, fill=c.body_color) 81 | foot_right = c.create_oval(250, 320, 330, 360, outline=c.body_color, fill=c.body_color) 82 | 83 | eye_left = c.create_oval(130, 110, 160, 170, outline='black', fill='white') 84 | pupil_left = c.create_oval(140, 145, 150, 155, outline='black', fill='black') 85 | eye_right = c.create_oval(230, 110, 260, 170, outline='black', fill='white') 86 | pupil_right = c.create_oval(240, 145, 250, 155, outline='black', fill='black') 87 | 88 | 89 | mouth_normal = c.create_line(170, 250, 200, 272, 230, 250, smooth=1, width=2, state=NORMAL) 90 | mouth_happy = c.create_line(170, 250, 200, 282, 230, 250, smooth=1, width=2, state=HIDDEN) 91 | mouth_sad = c.create_line(170, 250, 200, 232, 230, 250, smooth=1, width=2, state=HIDDEN) 92 | tongue_main = c.create_rectangle(170, 250, 230, 290, outline='red', fill='red', state=HIDDEN) 93 | tongue_tip = c.create_oval(170, 285, 230, 300, outline='red', fill='red', state=HIDDEN) 94 | 95 | cheek_left = c.create_oval(70, 180, 120, 230, outline='pink', fill='pink', state=HIDDEN) 96 | cheek_right = c.create_oval(280, 180, 330, 230, outline='pink', fill='pink', state=HIDDEN) 97 | 98 | c.pack() 99 | c.bind('', show_happy) 100 | c.bind('', hide_happy) 101 | c.bind('', cheeky) 102 | 103 | c.happy_level = 10 104 | c.eyes_crossed = False 105 | c.tongue_out = False 106 | 107 | root.after(1000, blink) 108 | root.after(5000, sad) 109 | root.mainloop() 110 | -------------------------------------------------------------------------------- /hacktoberfest__2022: -------------------------------------------------------------------------------- 1 | # A binary tree node 2 | 3 | 4 | class Node(): 5 | 6 | # A constructor to create a new node 7 | def __init__(self, data): 8 | self.data = data 9 | self.left = None 10 | self.right = None 11 | 12 | 13 | # constructTreeUtil.preIndex is a static variable of 14 | # function constructTreeUtil 15 | 16 | # Function to get the value of static variable 17 | # constructTreeUtil.preIndex 18 | def getPreIndex(): 19 | return constructTreeUtil.preIndex 20 | 21 | # Function to increment the value of static variable 22 | # constructTreeUtil.preIndex 23 | 24 | 25 | def incrementPreIndex(): 26 | constructTreeUtil.preIndex += 1 27 | 28 | # A recurseive function to construct Full from pre[]. 29 | # preIndex is used to keep track of index in pre[[]. 30 | 31 | 32 | def constructTreeUtil(pre, low, high): 33 | 34 | # Base Case 35 | if(low > high): 36 | return None 37 | 38 | # The first node in preorder traversal is root. So take 39 | # the node at preIndex from pre[] and make it root, 40 | # and increment preIndex 41 | root = Node(pre[getPreIndex()]) 42 | incrementPreIndex() 43 | 44 | # If the current subarray has onlye one element, 45 | # no need to recur 46 | if low == high: 47 | return root 48 | 49 | r_root = -1 50 | 51 | # Search for the first element greater than root 52 | for i in range(low, high+1): 53 | if (pre[i] > root.data): 54 | r_root = i 55 | break 56 | 57 | # If no elements are greater than the current root, 58 | # all elements are left children 59 | # so assign root appropriately 60 | if r_root == -1: 61 | r_root = getPreIndex() + (high - low) 62 | 63 | # Use the index of element found in preorder to divide 64 | # preorder array in two parts. Left subtree and right 65 | # subtree 66 | root.left = constructTreeUtil(pre, getPreIndex(), r_root-1) 67 | 68 | root.right = constructTreeUtil(pre, r_root, high) 69 | 70 | return root 71 | 72 | # The main function to construct BST from given preorder 73 | # traversal. This function mailny uses constructTreeUtil() 74 | 75 | 76 | def constructTree(pre): 77 | size = len(pre) 78 | constructTreeUtil.preIndex = 0 79 | return constructTreeUtil(pre, 0, size-1) 80 | 81 | 82 | def printInorder(root): 83 | if root is None: 84 | return 85 | printInorder(root.left) 86 | print (root.data,end=' ') 87 | printInorder(root.right) 88 | 89 | 90 | # Driver code 91 | pre = [10, 5, 1, 7, 40, 50] 92 | 93 | root = constructTree(pre) 94 | print ("Inorder traversal of the constructed tree:") 95 | printInorder(root) 96 | -------------------------------------------------------------------------------- /hailstone_Sequence.py: -------------------------------------------------------------------------------- 1 | hailstone_list = [] 2 | def hailstone(n): 3 | hailstone_list.append(int(n)) 4 | if n == 1: 5 | return hailstone_list 6 | while n != 1: 7 | if n % 2 == 0: 8 | return hailstone(int(n/2)) 9 | else: 10 | return hailstone(int(3*n + 1)) 11 | 12 | n = int(input("Enter the number:")) 13 | hailstone_list = [] 14 | hailstone_list = hailstone(n) 15 | print("Hailstone Sequence for n = {} is : {}".format(n, hailstone_list)) 16 | print("Number of steps is : ",len(hailstone_list)) 17 | -------------------------------------------------------------------------------- /heart/heart.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | 3 | # Creating a turtle object(pen) 4 | pen = turtle.Turtle() 5 | 6 | # Defining a method to draw curve 7 | def curve(): 8 | for i in range(200): 9 | 10 | # Defining step by step curve motion 11 | pen.right(1) 12 | pen.forward(1) 13 | 14 | # Defining method to draw a full heart 15 | def heart(): 16 | 17 | # Set the fill color to red 18 | pen.fillcolor('red') 19 | 20 | # Start filling the color 21 | pen.begin_fill() 22 | 23 | # Draw the left line 24 | pen.left(140) 25 | pen.forward(113) 26 | 27 | # Draw the left curve 28 | curve() 29 | pen.left(120) 30 | 31 | # Draw the right curve 32 | curve() 33 | 34 | # Draw the right line 35 | pen.forward(112) 36 | 37 | # Ending the filling of the color 38 | pen.end_fill() 39 | 40 | # Defining method to write text 41 | def txt(): 42 | 43 | # Move turtle to air 44 | pen.up() 45 | 46 | # Move turtle to a given position 47 | pen.setpos(-68, 95) 48 | 49 | # Move the turtle to the ground 50 | pen.down() 51 | 52 | # Set the text color to lightgreen 53 | pen.color('lightgreen') 54 | 55 | # Write the specified text in 56 | # specified font style and size 57 | pen.write("GeeksForGeeks", font=( 58 | "Verdana", 12, "bold")) 59 | 60 | 61 | # Draw a heart 62 | heart() 63 | 64 | # Write text 65 | txt() 66 | 67 | # To hide turtle 68 | pen.ht() 69 | -------------------------------------------------------------------------------- /helloworld.py: -------------------------------------------------------------------------------- 1 | print("hello world!") 2 | -------------------------------------------------------------------------------- /insertion_sort/insertion_sort.py: -------------------------------------------------------------------------------- 1 | 2 | def InsertionSort(arr, n): 3 | for i in range(1, n): 4 | key = arr[i] 5 | j = i-1 6 | while(j >= 0 and key < arr[j]): 7 | arr[j+1] = arr[j] 8 | j = j-1 9 | arr[j+1] = key 10 | 11 | 12 | l = [] 13 | print("Enter the size of array: ") 14 | a = int(input()) 15 | for i in range(a): 16 | n = random.randint(1, 100) 17 | l.append(n) 18 | 19 | InsertionSort(l, a) 20 | print(l) 21 | -------------------------------------------------------------------------------- /instagram downloader/README.md: -------------------------------------------------------------------------------- 1 | # Instagram Downloader 2 | This Script will download all photos & profile picture of any username (privacy : public) 3 | 4 | ## How to Use 5 | ``` 6 | pip install instaloader 7 | python igdown.py 8 | ``` 9 | -------------------------------------------------------------------------------- /instagram downloader/igdown.py: -------------------------------------------------------------------------------- 1 | import instaloader 2 | insta = instaloader.Instaloader() 3 | 4 | # Ask Username 5 | user = input("Enter the username: ") 6 | # Downloader Profile Pic 7 | insta.download_profile(user, profile_pic_only=True) 8 | # Download Photos 9 | insta.download_profile(user, profile_pic_only=False) 10 | -------------------------------------------------------------------------------- /instagram downloader/requirements.txt: -------------------------------------------------------------------------------- 1 | instaloader 2 | -------------------------------------------------------------------------------- /lcs/lcs.py: -------------------------------------------------------------------------------- 1 | # The longest common subsequence in Python 2 | 3 | 4 | # Function to find lcs_algo 5 | def lcs_algo(S1, S2, m, n): 6 | L = [[0 for x in range(n+1)] for x in range(m+1)] 7 | 8 | # Building the mtrix in bottom-up way 9 | for i in range(m+1): 10 | for j in range(n+1): 11 | if i == 0 or j == 0: 12 | L[i][j] = 0 13 | elif S1[i-1] == S2[j-1]: 14 | L[i][j] = L[i-1][j-1] + 1 15 | else: 16 | L[i][j] = max(L[i-1][j], L[i][j-1]) 17 | 18 | index = L[m][n] 19 | 20 | lcs_algo = [""] * (index+1) 21 | lcs_algo[index] = "" 22 | 23 | i = m 24 | j = n 25 | while i > 0 and j > 0: 26 | 27 | if S1[i-1] == S2[j-1]: 28 | lcs_algo[index-1] = S1[i-1] 29 | i -= 1 30 | j -= 1 31 | index -= 1 32 | 33 | elif L[i-1][j] > L[i][j-1]: 34 | i -= 1 35 | else: 36 | j -= 1 37 | 38 | # Printing the sub sequences 39 | print("S1 : " + S1 + "\nS2 : " + S2) 40 | print("LCS: " + "".join(lcs_algo)) 41 | 42 | 43 | S1 = "ACADB" 44 | S2 = "CBDA" 45 | m = len(S1) 46 | n = len(S2) 47 | lcs_algo(S1, S2, m, n) 48 | -------------------------------------------------------------------------------- /linearsearch_asad.py: -------------------------------------------------------------------------------- 1 | def linear_Search(list1, n, key): 2 | 3 | # Searching list1 sequentially 4 | for i in range(0, n): 5 | if (list1[i] == key): 6 | return i 7 | return -1 8 | 9 | 10 | list1 = [1 ,3, 5, 4, 7, 9] 11 | key = 7 12 | 13 | n = len(list1) 14 | res = linear_Search(list1, n, key) 15 | if(res == -1): 16 | print("Element not found") 17 | else: 18 | print("Element found at index: ", res) 19 | -------------------------------------------------------------------------------- /linkedList/linkedList.py: -------------------------------------------------------------------------------- 1 | # A single node of a singly linked list 2 | class Node: 3 | # constructor 4 | def __init__(self, data = None, next=None): 5 | self.data = data 6 | self.next = next 7 | 8 | # A Linked List class with a single head node 9 | class LinkedList: 10 | def __init__(self): 11 | self.head = None 12 | 13 | # insertion method for the linked list 14 | def insert(self, data): 15 | newNode = Node(data) 16 | if(self.head): 17 | current = self.head 18 | while(current.next): 19 | current = current.next 20 | current.next = newNode 21 | else: 22 | self.head = newNode 23 | 24 | # print method for the linked list 25 | def printLL(self): 26 | current = self.head 27 | while(current): 28 | print(current.data) 29 | current = current.next 30 | 31 | # Singly Linked List with insertion and print methods 32 | LL = LinkedList() 33 | LL.insert(3) 34 | LL.insert(4) 35 | LL.insert(5) 36 | LL.printLL() 37 | -------------------------------------------------------------------------------- /linkedlist.py: -------------------------------------------------------------------------------- 1 | #Represent a node of binary tree 2 | class Node: 3 | def __init__(self,data): 4 | self.data = data; 5 | self.left = None; 6 | self.right = None; 7 | 8 | class BinaryTreeToDLL: 9 | def __init__(self): 10 | #Represent the root of binary tree 11 | self.root = None; 12 | #Represent the head and tail of the doubly linked list 13 | self.head = None; 14 | self.tail = None; 15 | 16 | #convertbtToDLL() will convert the given binary tree to corresponding doubly linked list 17 | def convertbtToDLL(self, node): 18 | #Checks whether node is None 19 | if(node == None): 20 | return; 21 | 22 | #Convert left subtree to doubly linked list 23 | self.convertbtToDLL(node.left); 24 | 25 | #If list is empty, add node as head of the list 26 | if(self.head == None): 27 | #Both head and tail will point to node 28 | self.head = self.tail = node; 29 | #Otherwise, add node to the end of the list 30 | else: 31 | #node will be added after tail such that tail's right will point to node 32 | self.tail.right = node; 33 | #node's left will point to tail 34 | node.left = self.tail; 35 | #node will become new tail 36 | self.tail = node; 37 | 38 | #Convert right subtree to doubly linked list 39 | self.convertbtToDLL(node.right); 40 | 41 | #display() will print out the nodes of the list 42 | def display(self): 43 | #Node current will point to head 44 | current = self.head; 45 | if(self.head == None): 46 | print("List is empty"); 47 | return; 48 | print("Nodes of generated doubly linked list: "); 49 | while(current != None): 50 | #Prints each node by incrementing pointer. 51 | print(current.data), 52 | current = current.right; 53 | 54 | 55 | bt = BinaryTreeToDLL(); 56 | #Add nodes to the binary tree 57 | bt.root = Node(1); 58 | bt.root.left = Node(2); 59 | bt.root.right = Node(3); 60 | bt.root.left.left = Node(4); 61 | bt.root.left.right = Node(5); 62 | bt.root.right.left = Node(6); 63 | bt.root.right.right = Node(7); 64 | 65 | #Converts the given binary tree to doubly linked list 66 | bt.convertbtToDLL(bt.root); 67 | 68 | #Displays the nodes present in the list 69 | bt.display(); 70 | -------------------------------------------------------------------------------- /logistic_regression/logistic_regression.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """LAB4_logistic_regression.ipynb 3 | 4 | Automatically generated by Colaboratory. 5 | 6 | Original file is located at 7 | https://colab.research.google.com/drive/1T5Iw5fhbcq2sSoD_odJca-K-YHIeOeBF 8 | 9 | # #Logistic Regression 10 | 11 | #Let’s make the Logistic Regression model, predicting whether a user will 12 | #purchase the product or not. 13 | 14 | #Imputing Libraries 15 | 16 | #matplotlib. pyplot is a collection of functions that make matplotlib work like MATLAB 17 | #pandas library use for manipulation and analysis of data 18 | #numpy consit 0f multidimesional array objects 19 | """ 20 | 21 | import pandas as pd 22 | import numpy as np 23 | import matplotlib.pyplot as plt 24 | 25 | """# Loading dataset – User_Data""" 26 | 27 | dataset = pd.read_csv("Iris.csv") 28 | 29 | """Now, to predict whether a user will purchase the product or not, 30 | #one needs to find out the relationship between Age and Estimated Salary. 31 | #Here User ID and Gender are not important factors for finding out this. 32 | 33 | # input 34 | """ 35 | 36 | x = dataset.iloc[:, [2,3,4]].values 37 | 38 | x 39 | 40 | """only take column 2 and 3 as input 41 | 42 | # output 43 | """ 44 | 45 | y = dataset.iloc[:, 5].values 46 | 47 | y 48 | 49 | """only take column 4 as output""" 50 | 51 | dataset.shape 52 | 53 | """sae explain the size of rows and columns """ 54 | 55 | dataset.head(150) 56 | 57 | """only take first 100 values 58 | 59 | # spliting 60 | 61 | now we split the data into two parts for training and testing 75% for training nad 25% for testing 62 | """ 63 | 64 | from sklearn.model_selection import train_test_split 65 | 66 | xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size = 0.30, random_state =0) 67 | 68 | """#Now, it is very important to perform feature scaling here 69 | #because Age and Estimated Salary values lie in different ranges. 70 | #If we don’t scale the features 71 | #then Estimated Salary feature will dominate Age feature 72 | #when the model finds the nearest neighbor to a data point in data space. 73 | #Here once see that Age and Estimated salary features values are sacled 39.# and now there in the -1 to 1. 74 | #Hence, each feature will contribute equally in decision making 75 | #i.e. finalizing the hypothesis. 76 | 77 | # scaling 78 | """ 79 | 80 | from sklearn.preprocessing import StandardScaler 81 | sc_x = StandardScaler() 82 | xtrain = sc_x.fit_transform(xtrain) 83 | xtest = sc_x.transform(xtest) 84 | 85 | print (xtrain[0 : 50, :]) 86 | 87 | """Finally, we are training our Logistic Regression model""" 88 | 89 | from sklearn.linear_model import LogisticRegression 90 | classifier = LogisticRegression(random_state = 0) 91 | classifier.fit(xtrain, ytrain) 92 | 93 | """After training the model, it time to use it to do prediction on testing data""" 94 | 95 | y_pred = classifier.predict(xtest) 96 | 97 | y_pred 98 | 99 | ytest 100 | 101 | """# performance testing and accuracy""" 102 | 103 | from sklearn.metrics import confusion_matrix 104 | cm = confusion_matrix(ytest, y_pred) 105 | print ("Confusion Matrix : \n", cm) 106 | 107 | from sklearn.metrics import accuracy_score 108 | print ("Accuracy : ", accuracy_score(ytest, y_pred)) 109 | 110 | """# visualizing the performance of model""" 111 | 112 | from matplotlib.colors import ListedColormap 113 | X_set, y_set = xtest, ytest 114 | X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, 115 | stop = X_set[:, 0].max() + 1,step = 0.01), 116 | np.arange(start = X_set[:, 1].min() - 1, 117 | stop = X_set[:, 1].max() + 1, step = 0.01)) 118 | plt.contourf(X1, X2, classifier.predict( 119 | np.array([X1.ravel(), 120 | X2.ravel()]).T). 121 | reshape(X1.shape), alpha = 0.75, cmap = ListedColormap(('black', 'grey'))) 122 | plt.xlim(X1.min(), X1.max()) 123 | plt.ylim(X2.min(), X2.max()) 124 | for i, j in enumerate(np.unique(y_set)): 125 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 126 | c = ListedColormap(('red', 'green'))(i), label = j) 127 | plt.title('Classifier (Test set)') 128 | plt.xlabel('Age') 129 | plt.ylabel('Estimated Salary') 130 | plt.legend() 131 | plt.show() -------------------------------------------------------------------------------- /matrix.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.array([[1,2,3,4],[4,55,1,2], 4 | [8,3,20,19],[11,2,22,21]]) 5 | m = np.reshape(a,(4, 4)) 6 | print(m) 7 | 8 | # Accessing element 9 | print("\nAccessing Elements") 10 | print(a[1]) 11 | print(a[2][0]) 12 | 13 | # Adding Element 14 | m = np.append(m,[[1, 15,13,11]],0) 15 | print("\nAdding Element") 16 | print(m) 17 | 18 | # Deleting Element 19 | m = np.delete(m,[1],0) 20 | print("\nDeleting Element") 21 | print(m) 22 | -------------------------------------------------------------------------------- /music player: -------------------------------------------------------------------------------- 1 | #importing libraries 2 | from pygame import mixer 3 | from tkinter import * 4 | import tkinter.font as font 5 | from tkinter import filedialog 6 | 7 | 8 | 9 | #add many songs to the playlist of python mp3 player 10 | def addsongs(): 11 | #to open a file 12 | temp_song=filedialog.askopenfilenames(initialdir="Music/",title="Choose a song", filetypes=(("mp3 Files","*.mp3"),)) 13 | ##loop through every item in the list to insert in the listbox 14 | for s in temp_song: 15 | s=s.replace("C:/Users/DataFlair/python-mp3-music-player/","") 16 | songs_list.insert(END,s) 17 | 18 | def deletesong(): 19 | curr_song=songs_list.curselection() 20 | songs_list.delete(curr_song[0]) 21 | 22 | 23 | def Play(): 24 | song=songs_list.get(ACTIVE) 25 | song=f'C:/Users/lenovo/Desktop/DataFlair/Notepad/Music/{song}' 26 | mixer.music.load(song) 27 | mixer.music.play() 28 | #to pause the song 29 | def Pause(): 30 | mixer.music.pause() 31 | #to stop the song 32 | def Stop(): 33 | mixer.music.stop() 34 | songs_list.selection_clear(ACTIVE) 35 | #to resume the song 36 | def Resume(): 37 | mixer.music.unpause() 38 | #Function to navigate from the current song 39 | def Previous(): 40 | #to get the selected song index 41 | previous_one=songs_list.curselection() 42 | #to get the previous song index 43 | previous_one=previous_one[0]-1 44 | #to get the previous song 45 | temp2=songs_list.get(previous_one) 46 | temp2=f'C:/Users/DataFlair/python-mp3-music-player/{temp2}' 47 | mixer.music.load(temp2) 48 | mixer.music.play() 49 | songs_list.selection_clear(0,END) 50 | #activate new song 51 | songs_list.activate(previous_one) 52 | #set the next song 53 | songs_list.selection_set(previous_one) 54 | def Next(): 55 | #to get the selected song index 56 | next_one=songs_list.curselection() 57 | #to get the next song index 58 | next_one=next_one[0]+1 59 | #to get the next song 60 | temp=songs_list.get(next_one) 61 | temp=f'C:/Users/DataFlair/python-mp3-music-player/{temp}' 62 | mixer.music.load(temp) 63 | mixer.music.play() 64 | songs_list.selection_clear(0,END) 65 | #activate newsong 66 | songs_list.activate(next_one) 67 | #set the next song 68 | songs_list.selection_set(next_one) 69 | 70 | 71 | #creating the root window 72 | root=Tk() 73 | root.title('DataFlair Python MP3 Music player App ') 74 | #initialize mixer 75 | mixer.init() 76 | #create the listbox to contain songs 77 | songs_list=Listbox(root,selectmode=SINGLE,bg="black",fg="white",font=('arial',15),height=12,width=47,selectbackground="gray",selectforeground="black") 78 | songs_list.grid(columnspan=9) 79 | #font is defined which is to be used for the button font 80 | defined_font = font.Font(family='Helvetica') 81 | #play button 82 | play_button=Button(root,text="Play",width =7,command=Play) 83 | play_button['font']=defined_font 84 | play_button.grid(row=1,column=0) 85 | #pause button 86 | pause_button=Button(root,text="Pause",width =7,command=Pause) 87 | pause_button['font']=defined_font 88 | pause_button.grid(row=1,column=1) 89 | #stop button 90 | stop_button=Button(root,text="Stop",width =7,command=Stop) 91 | stop_button['font']=defined_font 92 | stop_button.grid(row=1,column=2) 93 | #resume button 94 | Resume_button=Button(root,text="Resume",width =7,command=Resume) 95 | Resume_button['font']=defined_font 96 | Resume_button.grid(row=1,column=3) 97 | #previous button 98 | previous_button=Button(root,text="Prev",width =7,command=Previous) 99 | previous_button['font']=defined_font 100 | previous_button.grid(row=1,column=4) 101 | #nextbutton 102 | next_button=Button(root,text="Next",width =7,command=Next) 103 | next_button['font']=defined_font 104 | next_button.grid(row=1,column=5) 105 | #menu 106 | my_menu=Menu(root) 107 | root.config(menu=my_menu) 108 | add_song_menu=Menu(my_menu) 109 | my_menu.add_cascade(label="Menu",menu=add_song_menu) 110 | add_song_menu.add_command(label="Add songs",command=addsongs) 111 | add_song_menu.add_command(label="Delete song",command=deletesong) 112 | mainloop() 113 | -------------------------------------------------------------------------------- /news narrator.py: -------------------------------------------------------------------------------- 1 | from logging.config import listen 2 | import speech_recognition as sr 3 | import pyttsx3 4 | from GoogleNews import GoogleNews 5 | 6 | news = GoogleNews() 7 | a = pyttsx3.init() 8 | speak_voice = a.getProperty('voices') 9 | a.setProperty('voice',speak_voice[1].id) 10 | # voice of female put 1 for male put 0 11 | recognizer = sr.Recognizer() 12 | 13 | def speak_news(): 14 | with sr.Microphone() as source: 15 | print("Firstly clearing out the background noises ....") 16 | recognizer.adjust_for_ambient_noise(source, duration=1) 17 | print("Tell me the topic for which you want the news...") 18 | listen_voice = recognizer.listen(source, timeout=1) 19 | print("Your voice has been recorded") 20 | 21 | try: 22 | news_txt = recognizer.recognize_google(listen_voice,language='en_US') 23 | news_txt = news_txt.lower() 24 | print("You message which you said is : ",format(news_txt)) 25 | except Exception as e: 26 | print(e) 27 | 28 | if 'headlines' in news_txt: 29 | a.say("Wait Getting headlines of today for you") 30 | a.runAndWait() 31 | news.get_news('Today news') 32 | news.result() 33 | b = news.gettext() 34 | print(*b[1:5],sep=',') 35 | 36 | if 'sports' in news_txt: 37 | a.say("Wait Getting sports news of today for you") 38 | a.runAndWait() 39 | news.get_news('Sports') 40 | news.result() 41 | b = news.gettext() 42 | print(*b[1:5],sep=',') 43 | 44 | if 'tech' in news_txt: 45 | a.say("Wait Getting Technology news of today for you") 46 | a.runAndWait() 47 | news.get_news('Tech') 48 | news.result() 49 | b = news.gettext() 50 | print(*b[1:5],sep=',') 51 | 52 | speak_news() 53 | -------------------------------------------------------------------------------- /node/node.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | # constructor 3 | def __init__(self, data, next=None): 4 | self.data = data 5 | self.next = next 6 | 7 | # Creating a single node 8 | first = Node(3) 9 | print(first.data) 10 | -------------------------------------------------------------------------------- /num_again/num_again.py: -------------------------------------------------------------------------------- 1 | # defining a function to calculate LCM 2 | def calculate_lcm(x, y): 3 | # selecting the greater number 4 | if x > y: 5 | greater = x 6 | else: 7 | greater = y 8 | while(True): 9 | if((greater % x == 0) and (greater % y == 0)): 10 | lcm = greater 11 | break 12 | greater += 1 13 | return lcm 14 | 15 | # taking input from users 16 | num1 = int(input("Enter first number: ")) 17 | num2 = int(input("Enter second number: ")) 18 | # printing the result for the users 19 | print("The L.C.M. of", num1,"and", num2,"is", calculate_lcm(num1, num2)) 20 | -------------------------------------------------------------------------------- /number_guessing_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | # to create a range of random numbers between 1-10 3 | n = random.randrange(1,100) 4 | # to take a user input to enter a number 5 | guess = int(input("Enter any number: ")) 6 | while n!= guess: # means if n is not equal to the input guess 7 | # if guess is smaller than n 8 | if guess < n: 9 | print("Too low") 10 | # to again ask for input 11 | guess = int(input("Enter number again: ")) 12 | # if guess is greater than n 13 | elif guess > n: 14 | print("Too high!") 15 | # to again ask for the user input 16 | guess = int(input("Enter number again: ")) 17 | # if guess gets equals to n terminate the while loop 18 | else: 19 | break 20 | print("you guessed it right!!") 21 | -------------------------------------------------------------------------------- /palindrome.py: -------------------------------------------------------------------------------- 1 | def isPalindrome(str): 2 | 3 | 4 | for i in range(0, int(len(str)/2)): 5 | if str[i] != str[len(str)-i-1]: 6 | return False 7 | return True 8 | 9 | 10 | s = "malayalam" 11 | ans = isPalindrome(s) 12 | 13 | if (ans): 14 | print("Yes") 15 | else: 16 | print("No") 17 | -------------------------------------------------------------------------------- /password_generator.py: -------------------------------------------------------------------------------- 1 | import random 2 | import string 3 | print('hello, Welcome to Password generator!') 4 | length = int(input('\nEnter the length of password: ')) 5 | lower = string.ascii_lowercase 6 | upper = string.ascii_uppercase 7 | num = string.digits 8 | symbols = string.punctuation 9 | all = lower + upper + num + symbols 10 | temp = random.sample(all,length) 11 | password = "".join(temp) 12 | all = string.ascii_letters + string.digits + string.punctuation 13 | pass = "".join(random.sample(all,length)) 14 | print(password) 15 | -------------------------------------------------------------------------------- /pattern.py: -------------------------------------------------------------------------------- 1 | def pattern(n): 2 | for i in range(n): 3 | for j in range(n): 4 | # printing stars 5 | print("* ",end="") 6 | print("\r") 7 | 8 | # take inputs 9 | n = int(input('Enter the number of rows: ')) 10 | 11 | # calling function 12 | pattern(n) 13 | -------------------------------------------------------------------------------- /pattern19/pattern19.py: -------------------------------------------------------------------------------- 1 | # Python program to print pattern G 2 | def Pattern(line): 3 | pat="" 4 | for i in range(0,line): 5 | for j in range(0,line): 6 | if ((j == 1 and i != 0 and i != line-1) or ((i == 0 or 7 | i == line-1) and j > 1 and j < line-2) or (i == ((line-1)/2) 8 | and j > line-5 and j < line-1) or (j == line-2 and 9 | i != 0 and i != line-1 and i >=((line-1)/2))): 10 | pat=pat+"*" 11 | else: 12 | pat=pat+" " 13 | pat=pat+"\n" 14 | return pat 15 | 16 | line = 7 17 | print(Pattern(line)) 18 | -------------------------------------------------------------------------------- /patternpyramid.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter the number of rows")) 2 | for i in range(0, n): 3 | for j in range(0, i + 1): 4 | print("* ", end="") 5 | print() -------------------------------------------------------------------------------- /pearson_correlation.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | movies = pd.read_csv("MoviesOnStreamingPlatforms_updated.csv") 3 | movies['Rotten Tomatoes'] = movies["Rotten Tomatoes"].str.replace("%", "").astype(float) 4 | movies.drop("Type", inplace=True, axis=1) 5 | correlations = movies.corr(method='pearson') 6 | # Correlation Between All The Features 7 | print(correlations) 8 | 9 | # Correlation Between A Particular column "Year" 10 | print(correlations["Year"]) 11 | 12 | # Visualizing Correlation 13 | import seaborn as sns 14 | 15 | import matplotlib.pyplot as plt 16 | sns.heatmap(correlations) 17 | plt.show() 18 | -------------------------------------------------------------------------------- /pencil_sketch.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | image = cv2.imread("dog.jpg") 3 | cv2.imshow("Dog", image) 4 | cv2.waitKey(0) 5 | gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 6 | cv2.imshow("New Dog", gray_image) 7 | cv2.waitKey(0) 8 | inverted_image = 255 - gray_image 9 | cv2.imshow("Inverted", inverted_image) 10 | cv2.waitKey() 11 | blurred = cv2.GaussianBlur(inverted_image, (21, 21), 0) 12 | inverted_blurred = 255 - blurred 13 | pencil_sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0) 14 | cv2.imshow("Sketch", pencil_sketch) 15 | cv2.waitKey(0) 16 | cv2.imshow("original image", image) 17 | cv2.imshow("pencil sketch", pencil_sketch) 18 | cv2.waitKey(0) 19 | -------------------------------------------------------------------------------- /perfect_no_in_range.py: -------------------------------------------------------------------------------- 1 | lower =int(input("enter lower range:")) 2 | upper =int(input("enter upper range:")) 3 | print(f"Perfect numbers between {lower} and {upper} :") 4 | for num in range(lower, upper): 5 | temp = num 6 | sum = 0 7 | for i in range(1, temp): 8 | if(temp % i == 0): 9 | sum = sum + i 10 | if (sum == num): 11 | print(num) 12 | -------------------------------------------------------------------------------- /perfectnumber.py: -------------------------------------------------------------------------------- 1 | num=int(input("Enter the number: ")) 2 | sum_v=0 3 | for i in range(1,num): 4 | if (num%i==0): 5 | sum_v=sum_v+i 6 | if(sum_v==num): 7 | print("The entered number is a perfect number") 8 | else: 9 | print("The entered number is not a perfect number" 10 | -------------------------------------------------------------------------------- /phone_number.py: -------------------------------------------------------------------------------- 1 | import phonenumbers as ph 2 | from phonenumbers import carrier 3 | from phonenumbers import geocoder 4 | from phonenumbers import timezone 5 | 6 | number = "+9185XXXXXXXX" 7 | number = ph.parse(number) 8 | print(timezone.time_zones_for_number(number)) 9 | print(carrier.name_for_number(number, "en")) 10 | print(geocoder.description_for_number(number, "en")) 11 | -------------------------------------------------------------------------------- /plaindrome/plaindrome.py: -------------------------------------------------------------------------------- 1 | Num = int(input("Enter a value:")) 2 | Temp = num 3 | Rev = 0 4 | while(num > 0): 5 | dig = num % 10 6 | revrev = rev * 10 + dig 7 | numnum = num // 10 8 | if(temp == rev): 9 | print("This value is a palindrome number!") 10 | else: 11 | print("This value is not a palindrome number!") 12 | -------------------------------------------------------------------------------- /pong_1/pong_1.py: -------------------------------------------------------------------------------- 1 | import pygame, sys 2 | import time 3 | import random 4 | 5 | pygame.init() 6 | 7 | window_ht = 600 8 | window_wt = 1000 9 | 10 | black = (0, 0 , 0) 11 | white = (255, 255, 255) 12 | red = (255, 0, 0) 13 | blue = (0, 255, 0) 14 | green = (0, 0 ,255) 15 | 16 | window = pygame.display.set_mode([window_wt,window_ht]) 17 | pygame.display.set_caption('Pong') 18 | 19 | screen = pygame.display.get_surface() 20 | 21 | #initial coordinates of the paddle 22 | rect_x = 500 23 | rect_y = 580 24 | 25 | #initial speed of the paddle 26 | rect_x_change = 0 27 | rect_y_change = 0 28 | 29 | #initial position of the ball 30 | ball_x = 50 31 | ball_y = 50 32 | 33 | ball_x_change = 5 34 | ball_y_change = 5 35 | 36 | score = 0 37 | 38 | def drawrect(screen,x,y): 39 | if x <= 0: 40 | x = 0 41 | if x >= 899: 42 | x = 899 43 | pygame.draw.rect(screen,red,[x,y,100,20]) 44 | 45 | # game's main loop 46 | done = False 47 | clock = pygame.time.Clock() 48 | FPS = 60 49 | 50 | while not done: 51 | for event in pygame.event.get(): 52 | if event.type == pygame.QUIT: 53 | done = True 54 | elif event.type == pygame.KEYDOWN: 55 | if event.key == pygame.K_LEFT: 56 | rect_x_change = -6 57 | elif event.key == pygame.K_RIGHT: 58 | rect_x_change = 6 59 | elif event.type == pygame.KEYUP: 60 | if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: 61 | rect_x_change = 0 62 | elif event.key == pygame.K_UP or event.key == pygame.K_DOWN: 63 | rect_y_change = 0 64 | 65 | screen.fill(black) 66 | 67 | rect_x += rect_x_change 68 | rect_y += rect_y_change 69 | 70 | ball_x += ball_x_change 71 | ball_y += ball_y_change 72 | 73 | 74 | if ball_x < 0: 75 | ball_x = 0 76 | ball_x_change = ball_x_change * -1 77 | elif ball_x > 985: 78 | ball_x = 985 79 | ball_x_change = ball_x_change * -1 80 | 81 | if ball_y < 0: 82 | ball_y = 0 83 | ball_y_change = ball_y_change * -1 84 | elif ball_x > rect_x and ball_x < rect_x +100 and ball_y == 565: 85 | ball_y_change = ball_y_change * -1 86 | score += 1 87 | FPS += 1 88 | elif ball_y > 600: 89 | ball_y_change = ball_y_change * -1 90 | score = 0 91 | FPS = 60 92 | pygame.draw.rect(screen,white,[ball_x,ball_y,15,15]) 93 | 94 | drawrect(screen, rect_x, rect_y) 95 | 96 | #score board 97 | font = pygame.font.SysFont('Calibri',15,False,False) 98 | text = font.render("Score = " + str(score), True, white) 99 | screen.blit(text,[800,100]) 100 | 101 | pygame.display.flip() 102 | clock.tick(FPS) 103 | 104 | pygame.quit() 105 | 106 | 107 | -------------------------------------------------------------------------------- /prime.py: -------------------------------------------------------------------------------- 1 | def fibonacci_recursion(my_val): 2 | if my_val <= 1: 3 | return my_val 4 | else: 5 | return(fibonacci_recursion(my_val-1) + fibonacci_recursion(my_val-2)) 6 | num_terms = 12 7 | print("The number of terms is ") 8 | print(num_terms) 9 | if num_terms <= 0: 10 | print("Enter a positive integer...") 11 | else: 12 | print("The Fibonacci sequence is :") 13 | for i in range(num_terms): 14 | print(fibonacci_recursion(i)) 15 | -------------------------------------------------------------------------------- /prime/prime.py: -------------------------------------------------------------------------------- 1 | # Program to check if a number is prime or not 2 | 3 | num = 29 4 | 5 | # To take input from the user 6 | #num = int(input("Enter a number: ")) 7 | 8 | # define a flag variable 9 | flag = False 10 | 11 | # prime numbers are greater than 1 12 | if num > 1: 13 | # check for factors 14 | for i in range(2, num): 15 | if (num % i) == 0: 16 | # if factor is found, set flag to True 17 | flag = True 18 | # break out of loop 19 | break 20 | 21 | # check if flag is True 22 | if flag: 23 | print(num, "is not a prime number") 24 | else: 25 | print(num, "is a prime number") -------------------------------------------------------------------------------- /pyautogui-SpiralDrawer/README.md: -------------------------------------------------------------------------------- 1 | # PyAutoGui Spiral Drawer 2 | 3 | This script drags the mouse in a square spiral shape in MS Paint (or any graphics drawing program) 4 | 5 | ### Prerequisites 6 | -pyautogui 7 | 8 | ### How to run the script 9 | python pyautogui.py 10 | 11 | ### Screenshot/GIF showing the sample use of the script 12 | ![example](square_spiral.png) 13 | 14 | ## *Credits* 15 | https://pyautogui.readthedocs.io/en/latest/ -------------------------------------------------------------------------------- /pyautogui-SpiralDrawer/pyautogui.py: -------------------------------------------------------------------------------- 1 | # This example drags the mouse in a square spiral shape in MS Paint (or any graphics drawing program) 2 | import pyautogui 3 | 4 | distance = 200 5 | while distance > 0: 6 | pyautogui.drag(distance, 0, duration=0.5) # move right 7 | distance -= 5 8 | pyautogui.drag(0, distance, duration=0.5) # move down 9 | pyautogui.drag(-distance, 0, duration=0.5) # move left 10 | distance -= 5 11 | pyautogui.drag(0, -distance, duration=0.5) # move up -------------------------------------------------------------------------------- /pyautogui-SpiralDrawer/square_spiral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavan-Kamthane/Python_Lang/554272f2fbe065a70abce0840779453795ecde71/pyautogui-SpiralDrawer/square_spiral.png -------------------------------------------------------------------------------- /pyramid,c++.txt: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int i, j, rows; 4 | printf("Enter the number of rows: "); 5 | scanf("%d", &rows); 6 | for (i = 1; i <= rows; ++i) { 7 | for (j = 1; j <= i; ++j) { 8 | printf("* "); 9 | } 10 | printf("\n"); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /python.py: -------------------------------------------------------------------------------- 1 | # Python3 code to Demonstrate Remove empty List 2 | # from List using list comprehension 3 | 4 | # Initializing list 5 | test_list = [5, 6, [], 3, [], [], 9] 6 | 7 | # printing original list 8 | print("The original list is : " + str(test_list)) 9 | 10 | # Remove empty List from List 11 | # using list comprehension 12 | res = [ele for ele in test_list if ele != []] 13 | 14 | # printing result 15 | print("List after empty list removal : " + str(res)) 16 | -------------------------------------------------------------------------------- /python111/python111.py: -------------------------------------------------------------------------------- 1 | # Python program to find the factorial of a number provided by the user. 2 | 3 | # change the value for a different result 4 | num = 7 5 | 6 | # To take input from the user 7 | #num = int(input("Enter a number: ")) 8 | 9 | factorial = 1 10 | 11 | # check if the number is negative, positive or zero 12 | if num < 0: 13 | print("Sorry, factorial does not exist for negative numbers") 14 | elif num == 0: 15 | print("The factorial of 0 is 1") 16 | else: 17 | for i in range(1,num + 1): 18 | factorial = factorial*i 19 | print("The factorial of",num,"is",factorial) 20 | -------------------------------------------------------------------------------- /quicksort/quicksort.py: -------------------------------------------------------------------------------- 1 | def partition(arr,low,high): 2 | i = ( low-1 ) 3 | pivot = arr[high] 4 | for j in range(low , high): 5 | if arr[j] <= pivot: 6 | i = i+1 7 | arr[i],arr[j] = arr[j],arr[i] 8 | arr[i+1],arr[high] = arr[high],arr[i+1] 9 | return ( i+1 ) 10 | 11 | def quickSort(arr,low,high): 12 | if low < high: 13 | pi = partition(arr,low,high) 14 | quickSort(arr, low, pi-1) 15 | quickSort(arr, pi+1, high) 16 | 17 | arr = [45,20,7,56,1,38,16] 18 | n = len(arr) 19 | 20 | quickSort(arr,0,n-1) 21 | 22 | print ("Sorted array is:") 23 | 24 | for i in range(n): 25 | print (arr[i],end=" ") -------------------------------------------------------------------------------- /quiz.py: -------------------------------------------------------------------------------- 1 | def check_guess(guess, answer): 2 | global score 3 | still_guessing = True 4 | attempt = 0 5 | while still_guessing and attempt < 3: 6 | if guess.lower() == answer.lower(): 7 | print("Correct Answer") 8 | score = score + 1 9 | still_guessing = False 10 | else: 11 | if attempt < 2: 12 | guess = input("Sorry Wrong Answer, try again") 13 | attempt = attempt + 1 14 | if attempt == 3: 15 | print("The Correct answer is ",answer ) 16 | 17 | score = 0 18 | print("Guess the Animal") 19 | guess1 = input("Which bear lives at the North Pole? ") 20 | check_guess(guess1, "polar bear") 21 | guess2 = input("Which is the fastest land animal? ") 22 | check_guess(guess2, "Cheetah") 23 | guess3 = input("Which is the larget animal? ") 24 | check_guess(guess3, "Blue Whale") 25 | print("Your Score is "+ str(score)) 26 | -------------------------------------------------------------------------------- /quiz_animal.py: -------------------------------------------------------------------------------- 1 | def check_guess(guess, answer): 2 | global score 3 | still_guessing = True 4 | attempt = 0 5 | while still_guessing and attempt < 3: 6 | if guess.lower() == answer.lower(): 7 | print("Correct Answer") 8 | score = score + 1 9 | still_guessing = False 10 | else: 11 | if attempt < 2: 12 | guess = input("Sorry Wrong Answer, try again") 13 | attempt = attempt + 1 14 | if attempt == 3: 15 | print("The Correct answer is ",answer ) 16 | 17 | score = 0 18 | print("Guess the Animal") 19 | guess1 = input("Which bear lives at the North Pole? ") 20 | check_guess(guess1, "polar bear") 21 | guess2 = input("Which is the fastest land animal? ") 22 | check_guess(guess2, "Cheetah") 23 | guess3 = input("Which is the larget animal? ") 24 | check_guess(guess3, "Blue Whale") 25 | print("Your Score is "+ str(score)) 26 | -------------------------------------------------------------------------------- /radixsort.py: -------------------------------------------------------------------------------- 1 | def countingSort(arr, exp1): 2 | 3 | n = len(arr) 4 | 5 | 6 | output = [0] * (n) 7 | 8 | 9 | count = [0] * (10) 10 | 11 | 12 | for i in range(0, n): 13 | index = (arr[i]/exp1) 14 | count[int((index)%10)] += 1 15 | 16 | 17 | for i in range(1,10): 18 | count[i] += count[i-1] 19 | 20 | 21 | i = n-1 22 | while i>=0: 23 | index = (arr[i]/exp1) 24 | output[ count[ int((index)%10) ] - 1] = arr[i] 25 | count[int((index)%10)] -= 1 26 | i -= 1 27 | 28 | 29 | i = 0 30 | for i in range(0,len(arr)): 31 | arr[i] = output[i] 32 | 33 | 34 | def radixSort(arr): 35 | 36 | 37 | max1 = max(arr) 38 | 39 | 40 | exp = 1 41 | while max1/exp > 0: 42 | countingSort(arr,exp) 43 | exp *= 10 44 | 45 | # Driver code to test above 46 | arr = [ 170, 45, 75, 90, 802, 24, 2, 66] 47 | radixSort(arr) 48 | 49 | for i in range(len(arr)): 50 | print(arr[i],end=" ") -------------------------------------------------------------------------------- /random_pass/random_pass.py: -------------------------------------------------------------------------------- 1 | from string import ascii_letters, digits 2 | from random import choice 3 | 4 | collection = ascii_letters + digits 5 | password = "" 6 | l = int(input("Length of password needed to be generated: ")) 7 | for i in range(l): 8 | password += choice(collection) 9 | print("Random Generated Password: ", password) 10 | -------------------------------------------------------------------------------- /recursive_factorial/recursive_factorial.py: -------------------------------------------------------------------------------- 1 | def recur_factorial(n): 2 | if n == 1: 3 | return n 4 | else: 5 | return n*recur_factorial(n-1) 6 | 7 | num = 7 8 | 9 | # check if the number is negative 10 | if num < 0: 11 | print("Sorry, factorial does not exist for negative numbers") 12 | elif num == 0: 13 | print("The factorial of 0 is 1") 14 | else: 15 | print("The factorial of", num, "is", recur_factorial(num)) -------------------------------------------------------------------------------- /separate audio/separate audio.py: -------------------------------------------------------------------------------- 1 | #comment: The main program [non-graphical interface] is here.. 2 | import moviepy 3 | import moviepy.editor 4 | video = moviepy.editor.VideoFileClip('#') # - path to video file. 5 | audio = video.audio 6 | audio.write_audiofile('#') # - path to audio file. 7 | -------------------------------------------------------------------------------- /shellsort.py: -------------------------------------------------------------------------------- 1 | # Shell sort in python 2 | 3 | 4 | def shellSort(array, n): 5 | 6 | # Rearrange elements at each n/2, n/4, n/8, ... intervals 7 | interval = n // 2 8 | while interval > 0: 9 | for i in range(interval, n): 10 | temp = array[i] 11 | j = i 12 | while j >= interval and array[j - interval] > temp: 13 | array[j] = array[j - interval] 14 | j -= interval 15 | 16 | array[j] = temp 17 | interval //= 2 18 | 19 | 20 | data = [9, 8, 3, 7, 5, 6, 4, 1] 21 | size = len(data) 22 | shellSort(data, size) 23 | print('Sorted Array in Ascending Order:') 24 | print(data) -------------------------------------------------------------------------------- /shruti.py: -------------------------------------------------------------------------------- 1 | #Python program to find factorial of given number 2 | def factorial(n): 3 | 4 | return 1 if (n==1 or n==0) else n * factorial(n - 1); 5 | 6 | # Driver Code 7 | num = 5; 8 | print("Factorial of",num,"is", 9 | factorial(num)) 10 | -------------------------------------------------------------------------------- /slidingwindow.py: -------------------------------------------------------------------------------- 1 | def maxSum(arr, k): 2 | n = len(arr) 3 | 4 | 5 | if n < k: 6 | print("Invalid") 7 | return -1 8 | 9 | 10 | window_sum = sum(arr[:k]) 11 | max_sum = window_sum 12 | 13 | 14 | for i in range(n - k): 15 | window_sum = window_sum - arr[i] + arr[i + k] 16 | max_sum = max(window_sum, max_sum) 17 | 18 | return max_sum 19 | 20 | 21 | arr = [16, 12, 9, 19, 11, 8] 22 | k = 3 23 | print(maxSum(arr, k)) 24 | -------------------------------------------------------------------------------- /snake game/snake game.py: -------------------------------------------------------------------------------- 1 | 2 | import pygame 3 | import time 4 | import random 5 | pygame.init() 6 | 7 | white = (255, 255, 255) 8 | yellow = (255, 255, 102) 9 | black = (0, 0, 0) 10 | red = (213, 50, 80) 11 | green = (0, 255, 0) 12 | blue = (50, 153, 213) 13 | 14 | dis_width = 600 15 | dis_height = 400 16 | 17 | dis = pygame.display.set_mode((dis_width, dis_height)) 18 | pygame.display.set_caption('Snake Game by Alby') 19 | 20 | clock = pygame.time.Clock() 21 | 22 | snake_block = 10 23 | snake_speed = 15 24 | 25 | font_style = pygame.font.SysFont("bahnschrift", 25) 26 | score_font = pygame.font.SysFont("comicsansms", 35) 27 | 28 | def our_snake(snake_block, snake_list): 29 | for x in snake_list: 30 | pygame.draw.rect(dis, black, [x[0], x[1], snake_block, snake_block]) 31 | 32 | 33 | def message(msg, color): 34 | mesg = font_style.render(msg, True, color) 35 | dis.blit(mesg, [dis_width / 6, dis_height / 3]) 36 | 37 | 38 | def gameLoop(): 39 | game_over = False 40 | game_close = False 41 | 42 | x1 = dis_width / 2 43 | y1 = dis_height / 2 44 | 45 | x1_change = 0 46 | y1_change = 0 47 | 48 | snake_List = [] 49 | Length_of_snake = 1 50 | 51 | foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0 52 | foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0 53 | 54 | while not game_over: 55 | 56 | while game_close == True: 57 | dis.fill(blue) 58 | message("You Lost! Press C-Play Again or Q-Quit", red) 59 | 60 | pygame.display.update() 61 | 62 | for event in pygame.event.get(): 63 | if event.type == pygame.KEYDOWN: 64 | if event.key == pygame.K_q: 65 | game_over = True 66 | game_close = False 67 | if event.key == pygame.K_c: 68 | gameLoop() 69 | 70 | for event in pygame.event.get(): 71 | if event.type == pygame.QUIT: 72 | game_over = True 73 | if event.type == pygame.KEYDOWN: 74 | if event.key == pygame.K_LEFT: 75 | x1_change = -snake_block 76 | y1_change = 0 77 | elif event.key == pygame.K_RIGHT: 78 | x1_change = snake_block 79 | y1_change = 0 80 | elif event.key == pygame.K_UP: 81 | y1_change = -snake_block 82 | x1_change = 0 83 | elif event.key == pygame.K_DOWN: 84 | y1_change = snake_block 85 | x1_change = 0 86 | 87 | if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0: 88 | game_close = True 89 | x1 += x1_change 90 | y1 += y1_change 91 | dis.fill(blue) 92 | pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block]) 93 | snake_Head = [] 94 | snake_Head.append(x1) 95 | snake_Head.append(y1) 96 | snake_List.append(snake_Head) 97 | if len(snake_List) > Length_of_snake: 98 | del snake_List[0] 99 | 100 | for x in snake_List[:-1]: 101 | if x == snake_Head: 102 | game_close = True 103 | 104 | our_snake(snake_block, snake_List) 105 | 106 | 107 | pygame.display.update() 108 | 109 | if x1 == foodx and y1 == foody: 110 | foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0 111 | foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0 112 | Length_of_snake += 1 113 | 114 | clock.tick(snake_speed) 115 | 116 | pygame.quit() 117 | quit() 118 | 119 | 120 | gameLoop() -------------------------------------------------------------------------------- /speech to text.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter.messagebox import showinfo 3 | from tkinter import filedialog 4 | from PIL import ImageTk, Image 5 | from gtts import gTTS 6 | import speech_recognition as sr 7 | import os 8 | 9 | root= Tk() 10 | root.title(' Automatic-Notes-Maker') 11 | root.geometry('500x500') 12 | root.resizable(0, 0) 13 | root.configure(bg='light blue') 14 | text1='' 15 | file_name =("E:/minor project/record2.wav") 16 | def recordvoice(): 17 | while True: 18 | text1 ='' 19 | r = sr.Recognizer() 20 | with sr.Microphone() as source: 21 | r.adjust_for_ambient_noise(source, duration=0.2) 22 | audio=r.listen(source) 23 | try: 24 | text1 = r.recognize_google(audio) 25 | print(text1) 26 | txt_area .insert(END, " ") 27 | except: 28 | pass 29 | return text1 30 | def Filevoice(): 31 | while True: 32 | file_name=filedialog.askopenfilename() 33 | text1 ='' 34 | r = sr.Recognizer() 35 | with sr.AudioFile(file_name) as source: # open file 36 | audio=r.listen(source) 37 | try: 38 | text1 = r.recognize_google(audio) 39 | print(text1) 40 | txt_area .insert(END, " ") 41 | 42 | except: 43 | pass 44 | return text1 45 | def Reset(): 46 | txt_area.delete(1.0,END) 47 | 48 | 49 | def savefile(): 50 | save_text = filedialog.asksaveasfile(mode='w', defaultextension='.txt') 51 | 52 | 53 | if save_text: 54 | 55 | text_area_text = txt_area.get('1.0', 'end-1c') 56 | 57 | save_text.write(text_area_text) 58 | save_text.close() 59 | 60 | '''path3="E:/minor project/images/i5.png" 61 | img1 = ImageTk.PhotoImage(Image.open(path3)) 62 | lebel_1=Label(root,bd=0,image=img1) 63 | lebel_1.place(x=170,y=90)''' 64 | 65 | button_icon1=PhotoImage(file="E:/minor project/images/i5.png") 66 | root.iconphoto(False,button_icon1) 67 | 68 | button_icon2=PhotoImage(file="E:/minor project/images/import.png") 69 | root.iconphoto(False,button_icon2) 70 | 71 | image_icon3=PhotoImage(file="E:/minor project/images/res1.png") 72 | root.iconphoto(False,image_icon3) 73 | d_btn=Button(root,text='Reset',compound=LEFT,width=170,font='arial 20 bold ',image=image_icon3,relief=SUNKEN,bg='white',activebackground='Gold',bd=10,command=Reset) 74 | d_btn.place(x=140,y=300) 75 | 76 | txt_area = Text(root, font=('times new rommon',15,'bold'), height=3, width=25) 77 | txt_area.place(x=120, y=200) 78 | 79 | recordbutton = Button(root,compound=LEFT,width=100 ,font='arial 9 bold',text='Recording', bg='#9B755F',image=button_icon1,activebackground="gold", command=lambda: txt_area .insert(END, recordvoice())) 80 | recordbutton.place(x=50, y=50) 81 | filebutton = Button(root,compound=LEFT,width=100 ,font='arial 10 bold',text='IMport', bg='#9B755F',image=button_icon2,activebackground="gold", command=lambda: txt_area .insert(END, Filevoice())) 82 | filebutton.place(x=300, y=50) 83 | 84 | Label(root, text=' automatic notes maker ',font="arial 20", bg='gold').place(x=110, y=0) 85 | 86 | save_button = Button(root, text='save', font="arial 25", bg='light green', command=lambda: savefile()) 87 | save_button.place(x=200, y=400) 88 | 89 | root.update() 90 | root.mainloop() 91 | -------------------------------------------------------------------------------- /split_and_join_string/split_and_join_string.py: -------------------------------------------------------------------------------- 1 | # Python program to split a string and 2 | # join it using different delimiter 3 | 4 | def split_string(string): 5 | 6 | # Split the string based on space delimiter 7 | list_string = string.split(' ') 8 | 9 | return list_string 10 | 11 | def join_string(list_string): 12 | 13 | # Join the string based on '-' delimiter 14 | string = '-'.join(list_string) 15 | 16 | return string 17 | 18 | # Driver Function 19 | if __name__ == '__main__': 20 | string = 'Geeks for Geeks' 21 | 22 | # Splitting a string 23 | list_string = split_string(string) 24 | print(list_string) 25 | 26 | # Join list of strings into one 27 | new_string = join_string(list_string) 28 | print(new_string) 29 | -------------------------------------------------------------------------------- /stringtodatetime.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | my_date_string = "Mar 11 2011 11:31AM" 4 | 5 | datetime_object = datetime.strptime(my_date_string, '%b %d %Y %I:%M%p') 6 | 7 | print(type(datetime_object)) 8 | print(datetime_object) -------------------------------------------------------------------------------- /text.py: -------------------------------------------------------------------------------- 1 | from json.tool import main 2 | import string 3 | import random 4 | 5 | if __name__ =="__main__": 6 | s1 = string.ascii_letters 7 | 8 | s2 =string.ascii_uppercase 9 | 10 | s3 =string.digits 11 | 12 | s4 =string.punctuation 13 | 14 | plen= int(input("Enter the length of your password\n ")) 15 | s =[] 16 | s.extend(list(s1)) 17 | s.extend(list(s2)) 18 | s.extend(list(s3)) 19 | s.extend(list(s4)) 20 | 21 | random.shuffle(s) 22 | print("YOUR PASSWORD IS : ") 23 | 24 | print("".join(s[0:plen])) 25 | -------------------------------------------------------------------------------- /time_calculator(1)/time_calculator (1).py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def get_days_later(days): 4 | """ Helper function to format days later""" 5 | if days == 1: 6 | return "(next day)" 7 | elif days > 1: 8 | return f"({days} days later)" 9 | return "" 10 | 11 | 12 | def add_time(start, duration, day=False): 13 | week_days = [ 14 | 'monday', 'tuesday', 15 | 'wednesday', 'thursday', 16 | 'friday', 'saturday', 17 | 'sunday' 18 | ] 19 | 20 | days_later = 0 21 | one_day = 24 22 | half_day = 12 23 | hours, mins = start.split(":") 24 | mins, period = mins.split(" ") 25 | dh, dm = duration.split(":") 26 | 27 | #CLEAN DATA 28 | hours = int(hours) # start hour 29 | mins = int(mins) # start min 30 | dh = int(dh) # duration hours 31 | dm = int(dm) # duration mins 32 | period = period.strip().lower() # AM or PM" 33 | 34 | # GET TOTAL HOURS AND MINUTES 35 | total_mins = mins + dm 36 | total_hours = hours + dh 37 | 38 | #SHIFT MINUTES TO HOUR IF ITS OVER 60 39 | if total_mins >= 60: 40 | total_hours += int(total_mins / 60) 41 | total_mins = int(total_mins % 60) 42 | 43 | if dh or dm: # only run if duration has hr or mins 44 | if period == "pm" and total_hours > half_day: 45 | #^- night time changing to another day 46 | #^- only run on PM , since AM to AM is 24hrs 47 | # so there is no need to change it 48 | if total_hours % one_day >= 1.0: 49 | days_later += 1 # over 24hr then add the days 50 | 51 | if total_hours >= half_day: 52 | hours_left = total_hours / one_day 53 | days_later += int(hours_left) 54 | #EX: 54hr / 24 = 2.25 days <-- append 2 days 55 | #EX: 36hr / 24 = 1.5 days <-- append 1 days 56 | 57 | tth = total_hours 58 | while True: 59 | # constantly reverse period untils 60 | # total_hours are less than half a day 61 | if tth < half_day: 62 | break 63 | if tth >= half_day: 64 | if period == "am": 65 | period = "pm" 66 | elif period == "pm": 67 | period = "am" 68 | tth -= half_day 69 | 70 | # RE-ADJUST HRS AND MIN 71 | # Above.. we already taken care of the days 72 | # so now we need to remove the days from the hrs and keep whats left. 73 | # EX: hr % oneday --> 55hr % 24 = 7 remaining --> hr=7 74 | remaining_hours = int(total_hours % half_day) or hours + 1 75 | remaining_mins = int(total_mins % 60) 76 | 77 | # Format the results 78 | results = f'{remaining_hours}:{remaining_mins:02} {period.upper()}' 79 | if day: # add day of the week 80 | day = day.strip().lower() 81 | selected_day = int((week_days.index(day) + days_later) % 7) 82 | current_day = week_days[selected_day] 83 | results += f', {current_day.title()} {get_days_later(days_later)}' 84 | 85 | else: # add days later 86 | results = " ".join((results, get_days_later(days_later))) 87 | 88 | return results.strip() 89 | 90 | 91 | 92 | # Call the add_time function with required inputs. 93 | # Start will be start time like "3:32 AM/PM" 94 | # Duration will be hours and minutes, "2:40" 95 | # E.g = add_time("3:32 PM", "12:05", Monday) -------------------------------------------------------------------------------- /tower_of_Hanoi/tower_of_Hanoi.py: -------------------------------------------------------------------------------- 1 | def toh(n,source,helper,destination): 2 | if(n==1): 3 | print("the disk will move from ",source," to ",destination) 4 | return 5 | toh(n-1,source,helper,destination) 6 | print("the disk ", n, " will move from ",source," to ",destination) 7 | toh(n-1,helper,destination,source) 8 | n=4 9 | toh(n,source,helper,destination) 10 | -------------------------------------------------------------------------------- /twitter scrape/scrape.py: -------------------------------------------------------------------------------- 1 | # Before scraping tweets using Python, you need access via Twitter's API. This access is easily attainable through Twitter's developer platform https://developer.twitter.com/en. 2 | 3 | !pip install tweepy 4 | import tweepy 5 | 6 | # Input API credentials from Twitter app developer account 7 | consumer_key= 'insert' 8 | consumer_secret= 'insert' 9 | access_token= 'insert' 10 | access_token_secret= 'insert' 11 | 12 | # Create an OAuthHandler instance and pass keys 13 | auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 14 | auth.set_access_token(access_token, access_token_secret) 15 | api = tweepy.API(auth,wait_on_rate_limit=True,wait_on_rate_limit_notify=True) 16 | 17 | # Scrape 10 tweets from a user's account. You can scrape more by increasing count size 18 | posts = api.user_timeline(screen_name = "@user", count = 10, lang ="en", tweet_mode="extended") 19 | 20 | # Create dataframe 21 | df = pd.DataFrame(data =[tweet.text for tweet in posts], columns = ["Tweet"]) 22 | -------------------------------------------------------------------------------- /vowel.py: -------------------------------------------------------------------------------- 1 | print(end="Enter a Character: ") 2 | c = input() 3 | 4 | size = len(c) 5 | if size>1: 6 | print("\nInvalid Input!") 7 | else: 8 | if (c>='a' and c<='z') or (c>='A' and c<='Z'): 9 | if c=='a' or c=='e' or c=='i' or c=='o' or c=='u': 10 | print("\n\"" +c+ "\" is a Vowel") 11 | elif c=='A' or c=='E' or c=='I' or c=='O' or c=='U': 12 | print("\n\"" +c+ "\" is a Vowel") 13 | else: 14 | print("\n\"" +c+ "\" is a Consonant") 15 | else: 16 | print("\n\"" +c+ "\" is neither a Vowel nor a Consonant") 17 | -------------------------------------------------------------------------------- /warshall/warshall.py: -------------------------------------------------------------------------------- 1 | # Floyd Warshall Algorithm in python 2 | 3 | 4 | # The number of vertices 5 | nV = 4 6 | 7 | INF = 999 8 | 9 | 10 | # Algorithm implementation 11 | def floyd_warshall(G): 12 | distance = list(map(lambda i: list(map(lambda j: j, i)), G)) 13 | 14 | # Adding vertices individually 15 | for k in range(nV): 16 | for i in range(nV): 17 | for j in range(nV): 18 | distance[i][j] = min(distance[i][j], distance[i][k] + distance[k][j]) 19 | print_solution(distance) 20 | 21 | 22 | # Printing the solution 23 | def print_solution(distance): 24 | for i in range(nV): 25 | for j in range(nV): 26 | if(distance[i][j] == INF): 27 | print("INF", end=" ") 28 | else: 29 | print(distance[i][j], end=" ") 30 | print(" ") 31 | 32 | 33 | G = [[0, 3, INF, 5], 34 | [2, 0, INF, 4], 35 | [INF, 1, 0, INF], 36 | [INF, INF, 2, 0]] 37 | floyd_warshall(G) 38 | --------------------------------------------------------------------------------