├── Age Calculator.py ├── BMI Calculator.py ├── Calculator GUI.py ├── Card Game.py ├── Count Capital Letters in a File.py ├── Create Amazing Graphics with Python.py ├── Create Font Art using Python.py ├── Create a Quiz Game.py ├── Create an Invoice.py ├── Defang IP Address using Python.py ├── Dice Roll Simulator with Python.py ├── Digital Clock.py ├── Digital clock using Python.py ├── Fidget Spinner Game.py ├── Game of Life with Python.py ├── Get Live Covid-19 Data.py ├── Indian Flag using Python.py ├── Internet Speed Test using Python.py ├── LCM using Python.py ├── Live Weather Updates.py ├── Merge Sort using Python.py ├── Monty Hall Simulator.py ├── Music Player GUI.py ├── Number Guessing Game with Python.py ├── Password Authentication using Python.py ├── Pencil Sketch.py ├── Pick a Random Card.py ├── Print a Calendar using Python.py ├── Pyramid Pattern.py ├── Python Program to Count Most Frequent Words in a File.py ├── Python Program to Generate Password.py ├── QR Code using Python.py ├── README.md ├── Real-time Currency Converter.py ├── Resume Scanner.py ├── Rock Paper and Scissors with Python.py ├── Screen Pet.py ├── Send Automatic Emails.py ├── Send Instagram Messages using Python.py ├── Shutdown Computer using Python.py ├── Snake Game with Python.py ├── Sorting_Visualizer.py ├── Text to Handwriting using Python.py ├── Treemap using Python.py ├── URL Shortener.py ├── Video to Audio Converter.py ├── Voice Recorder using Python.py ├── Web Scraping to Create a Dataset using Python.py ├── Wifi password using python.py ├── currency-converter-project.py └── passwordgenerator.py /Age Calculator.py: -------------------------------------------------------------------------------- 1 | def ageCalculator(y, m, d): 2 | import datetime 3 | today = datetime.datetime.now().date() 4 | dob = datetime.date(y, m, d) 5 | age = int((today-dob).days / 365.25) 6 | print(age) 7 | 8 | 9 | print("Enter Your DOB in yy-mm-dd format: "); 10 | y = int(input("Enter Year: ")); 11 | m = int(input("Enter Month: ")); 12 | d = int(input("Enter Date: ")); 13 | 14 | ageCalculator(y, m, d) 15 | #ageCalculator(1998, 9, 3) -------------------------------------------------------------------------------- /BMI Calculator.py: -------------------------------------------------------------------------------- 1 | #Enter the required parameters 2 | Height=float(input("Enter your height in centimeters: ")); 3 | Weight=float(input("Enter your Weight in Kg: ")); 4 | 5 | #Convert to req. metric 6 | Height = Height/100; 7 | 8 | #Calculate BMI value 9 | BMI=Weight/(Height*Height) 10 | print("your Body Mass Index is: ",BMI); 11 | 12 | #Return a message about your health. 13 | if(BMI>0): 14 | if(BMI<=16): 15 | print("you are severely underweight") 16 | elif(BMI<=18.5): 17 | print("you are underweight") 18 | elif(BMI<=25): 19 | print("you are Healthy") 20 | elif(BMI<=30): 21 | print("you are overweight") 22 | else: print("you are severely overweight") 23 | else:("enter valid details") -------------------------------------------------------------------------------- /Calculator GUI.py: -------------------------------------------------------------------------------- 1 | ##Kivy is a graphical user interface opensource Python library that allows you to develop multi-platform applications on Windows, macOS, Android, iOS, Linux, and Raspberry-Pi. 2 | from kivy.app import App 3 | from kivy.uix.button import Button 4 | from kivy.uix.boxlayout import BoxLayout 5 | from kivy.uix.gridlayout import GridLayout 6 | from kivy.uix.label import Label 7 | 8 | class myApp(App): 9 | def build(self): 10 | root_widget = BoxLayout(orientation='vertical') 11 | output_label = Label(size_hint_y = 0.75, font_size=50) 12 | button_symbols = ('1', '2', '3', '+', 13 | '4', '5', '6', '-', 14 | '7', '8', '9', '.', 15 | '0', '*', '/', '=') 16 | button_grid = GridLayout(cols=4, size_hint_y=2) 17 | 18 | for symbol in button_symbols: 19 | button_grid.add_widget(Button(text=symbol)) 20 | 21 | clear_button = Button(text = 'Clear', size_hint_y=None, height=100) 22 | 23 | def print_button_text(instance): 24 | output_label.text += instance.text 25 | 26 | for button in button_grid.children[1:]: 27 | button.bind(on_press=print_button_text) 28 | 29 | def resize_label_text(label, new_height): 30 | label.fontsize = 0.5*label.height 31 | 32 | output_label.bind(height=resize_label_text) 33 | 34 | def evaluate_result(instance): 35 | try: 36 | output_label.text = str(eval(output_label.text)) 37 | except SyntaxError: 38 | output_label.text = 'Python Syntax error!' 39 | 40 | button_grid.children[0].bind(on_press=evaluate_result) 41 | 42 | def clear_label(instance): 43 | output_label.text = " " 44 | 45 | clear_button.bind(on_press=clear_label) 46 | 47 | root_widget.add_widget(output_label) 48 | root_widget.add_widget(button_grid) 49 | root_widget.add_widget(clear_button) 50 | return root_widget 51 | 52 | myApp().run() 53 | -------------------------------------------------------------------------------- /Card Game.py: -------------------------------------------------------------------------------- 1 | from random import shuffle 2 | 3 | 4 | class Card: 5 | suits = ["spades", 6 | "hearts", 7 | "diamonds", 8 | "clubs"] 9 | 10 | values = [None, None,"2", "3", 11 | "4", "5", "6", "7", 12 | "8", "9", "10", 13 | "Jack", "Queen", 14 | "King", "Ace"] 15 | 16 | def __init__(self, v, s): 17 | """suit + value are ints""" 18 | self.value = v 19 | self.suit = s 20 | 21 | def __lt__(self, c2): 22 | if self.value < c2.value: 23 | return True 24 | if self.value == c2.value: 25 | if self.suit < c2.suit: 26 | return True 27 | else: 28 | return False 29 | return False 30 | 31 | def __gt__(self, c2): 32 | if self.value > c2.value: 33 | return True 34 | if self.value == c2.value: 35 | if self.suit > c2.suit: 36 | return True 37 | else: 38 | return False 39 | return False 40 | 41 | def __repr__(self): 42 | v = self.values[self.value] +\ 43 | " of " + \ 44 | self.suits[self.suit] 45 | return v 46 | 47 | 48 | class Deck: 49 | def __init__(self): 50 | self.cards = [] 51 | for i in range(2, 15): 52 | for j in range(4): 53 | self.cards\ 54 | .append(Card(i, 55 | j)) 56 | shuffle(self.cards) 57 | 58 | def rm_card(self): 59 | if len(self.cards) == 0: 60 | return 61 | return self.cards.pop() 62 | 63 | 64 | class Player: 65 | def __init__(self, name): 66 | self.wins = 0 67 | self.card = None 68 | self.name = name 69 | 70 | 71 | class Game: 72 | def __init__(self): 73 | name1 = input("p1 name ") 74 | name2 = input("p2 name ") 75 | self.deck = Deck() 76 | self.p1 = Player(name1) 77 | self.p2 = Player(name2) 78 | 79 | def wins(self, winner): 80 | w = "{} wins this round" 81 | w = w.format(winner) 82 | print(w) 83 | 84 | def draw(self, p1n, p1c, p2n, p2c): 85 | d = "{} drew {} {} drew {}" 86 | d = d.format(p1n, 87 | p1c, 88 | p2n, 89 | p2c) 90 | print(d) 91 | 92 | def play_game(self): 93 | cards = self.deck.cards 94 | print("beginning War!") 95 | while len(cards) >= 2: 96 | m = "q to quit. Any " + \ 97 | "key to play:" 98 | response = input(m) 99 | if response == 'q': 100 | break 101 | p1c = self.deck.rm_card() 102 | p2c = self.deck.rm_card() 103 | p1n = self.p1.name 104 | p2n = self.p2.name 105 | self.draw(p1n, 106 | p1c, 107 | p2n, 108 | p2c) 109 | if p1c > p2c: 110 | self.p1.wins += 1 111 | self.wins(self.p1.name) 112 | else: 113 | self.p2.wins += 1 114 | self.wins(self.p2.name) 115 | 116 | win = self.winner(self.p1, 117 | self.p2) 118 | print("War is over.{} wins" 119 | .format(win)) 120 | 121 | def winner(self, p1, p2): 122 | if p1.wins > p2.wins: 123 | return p1.name 124 | if p1.wins < p2.wins: 125 | return p2.name 126 | return "It was a tie!" 127 | 128 | game = Game() 129 | game.play_game() -------------------------------------------------------------------------------- /Count Capital Letters in a File.py: -------------------------------------------------------------------------------- 1 | with open("text.txt") as file: 2 | count = 0 3 | text = file.read() 4 | for i in text: 5 | if i.isupper(): 6 | count += 1 7 | print(count) -------------------------------------------------------------------------------- /Create Amazing Graphics with Python.py: -------------------------------------------------------------------------------- 1 | import turtle as tu 2 | 3 | roo = tu.Turtle() # Turtle object 4 | wn = tu.Screen() # Screen Object 5 | wn.bgcolor("black") # Screen Bg color 6 | wn.title("Fractal Tree Pattern") 7 | roo.left(90) # moving the turtle 90 degrees towards left 8 | roo.speed(20) # setting the speed of the turtle 9 | 10 | 11 | def draw(l): # recursive function taking length 'l' as argument 12 | if (l < 10): 13 | return 14 | else: 15 | 16 | roo.pensize(2) # Setting Pensize 17 | roo.pencolor("yellow") # Setting Pencolor as yellow 18 | roo.forward(l) # moving turtle forward by 'l' 19 | roo.left(30) # moving the turtle 30 degrees towards left 20 | draw(3 * l / 4) # drawing a fractal on the left of the turtle object 'roo' with 3/4th of its length 21 | roo.right(60) # moving the turtle 60 degrees towards right 22 | draw(3 * l / 4) # drawing a fractal on the right of the turtle object 'roo' with 3/4th of its length 23 | roo.left(30) # moving the turtle 30 degrees towards left 24 | roo.pensize(2) 25 | roo.backward(l) # returning the turtle back to its original psition 26 | 27 | 28 | draw(20) # drawing 20 times 29 | 30 | roo.right(90) 31 | roo.speed(2000) 32 | 33 | 34 | # recursion 35 | def draw(l): 36 | if (l < 10): 37 | return 38 | else: 39 | roo.pensize(2) 40 | roo.pencolor("magenta") # magenta 41 | roo.forward(l) 42 | roo.left(30) 43 | draw(3 * l / 4) 44 | roo.right(60) 45 | draw(3 * l / 4) 46 | roo.left(30) 47 | roo.pensize(2) 48 | roo.backward(l) 49 | 50 | 51 | draw(20) 52 | 53 | roo.left(270) 54 | roo.speed(2000) 55 | 56 | 57 | # recursion 58 | def draw(l): 59 | if (l < 10): 60 | return 61 | else: 62 | roo.pensize(2) 63 | roo.pencolor("red") # red 64 | roo.forward(l) 65 | roo.left(30) 66 | draw(3 * l / 4) 67 | roo.right(60) 68 | draw(3 * l / 4) 69 | roo.left(30) 70 | roo.pensize(2) 71 | roo.backward(l) 72 | 73 | 74 | draw(20) 75 | 76 | roo.right(90) 77 | roo.speed(2000) 78 | 79 | 80 | # recursion 81 | def draw(l): 82 | if (l < 10): 83 | return 84 | else: 85 | roo.pensize(2) 86 | roo.pencolor('#FFF8DC') # white 87 | roo.forward(l) 88 | roo.left(30) 89 | draw(3 * l / 4) 90 | roo.right(60) 91 | draw(3 * l / 4) 92 | roo.left(30) 93 | roo.pensize(2) 94 | roo.backward(l) 95 | 96 | 97 | draw(20) 98 | 99 | 100 | ######################################################## 101 | 102 | def draw(l): 103 | if (l < 10): 104 | return 105 | else: 106 | 107 | roo.pensize(3) 108 | roo.pencolor("lightgreen") # lightgreen 109 | roo.forward(l) 110 | roo.left(30) 111 | draw(4 * l / 5) 112 | roo.right(60) 113 | draw(4 * l / 5) 114 | roo.left(30) 115 | roo.pensize(3) 116 | roo.backward(l) 117 | 118 | 119 | draw(40) 120 | 121 | roo.right(90) 122 | roo.speed(2000) 123 | 124 | 125 | # recursion 126 | def draw(l): 127 | if (l < 10): 128 | return 129 | else: 130 | roo.pensize(3) 131 | roo.pencolor("red") # red 132 | roo.forward(l) 133 | roo.left(30) 134 | draw(4 * l / 5) 135 | roo.right(60) 136 | draw(4 * l / 5) 137 | roo.left(30) 138 | roo.pensize(3) 139 | roo.backward(l) 140 | 141 | 142 | draw(40) 143 | 144 | roo.left(270) 145 | roo.speed(2000) 146 | 147 | 148 | # recursion 149 | def draw(l): 150 | if (l < 10): 151 | return 152 | else: 153 | roo.pensize(3) 154 | roo.pencolor("yellow") # yellow 155 | roo.forward(l) 156 | roo.left(30) 157 | draw(4 * l / 5) 158 | roo.right(60) 159 | draw(4 * l / 5) 160 | roo.left(30) 161 | roo.pensize(3) 162 | roo.backward(l) 163 | 164 | 165 | draw(40) 166 | 167 | roo.right(90) 168 | roo.speed(2000) 169 | 170 | 171 | # recursion 172 | def draw(l): 173 | if (l < 10): 174 | return 175 | else: 176 | roo.pensize(3) 177 | roo.pencolor('#FFF8DC') # white 178 | roo.forward(l) 179 | roo.left(30) 180 | draw(4 * l / 5) 181 | roo.right(60) 182 | draw(4 * l / 5) 183 | roo.left(30) 184 | roo.pensize(3) 185 | roo.backward(l) 186 | 187 | 188 | draw(40) 189 | 190 | 191 | ######################################################## 192 | def draw(l): 193 | if (l < 10): 194 | return 195 | else: 196 | 197 | roo.pensize(2) 198 | roo.pencolor("cyan") # cyan 199 | roo.forward(l) 200 | roo.left(30) 201 | draw(6 * l / 7) 202 | roo.right(60) 203 | draw(6 * l / 7) 204 | roo.left(30) 205 | roo.pensize(2) 206 | roo.backward(l) 207 | 208 | 209 | draw(60) 210 | 211 | roo.right(90) 212 | roo.speed(2000) 213 | 214 | 215 | # recursion 216 | def draw(l): 217 | if (l < 10): 218 | return 219 | else: 220 | roo.pensize(2) 221 | roo.pencolor("yellow") # yellow 222 | roo.forward(l) 223 | roo.left(30) 224 | draw(6 * l / 7) 225 | roo.right(60) 226 | draw(6 * l / 7) 227 | roo.left(30) 228 | roo.pensize(2) 229 | roo.backward(l) 230 | 231 | 232 | draw(60) 233 | 234 | roo.left(270) 235 | roo.speed(2000) 236 | 237 | 238 | # recursion 239 | def draw(l): 240 | if (l < 10): 241 | return 242 | else: 243 | roo.pensize(2) 244 | roo.pencolor("magenta") # magenta 245 | roo.forward(l) 246 | roo.left(30) 247 | draw(6 * l / 7) 248 | roo.right(60) 249 | draw(6 * l / 7) 250 | roo.left(30) 251 | roo.pensize(2) 252 | roo.backward(l) 253 | 254 | 255 | draw(60) 256 | 257 | roo.right(90) 258 | roo.speed(2000) 259 | 260 | 261 | # recursion 262 | def draw(l): 263 | if (l < 10): 264 | return 265 | else: 266 | roo.pensize(2) 267 | roo.pencolor('#FFF8DC') # white 268 | roo.forward(l) 269 | roo.left(30) 270 | draw(6 * l / 7) 271 | roo.right(60) 272 | draw(6 * l / 7) 273 | roo.left(30) 274 | roo.pensize(2) 275 | roo.backward(l) 276 | 277 | 278 | draw(60) 279 | wn.exitonclick() -------------------------------------------------------------------------------- /Create Font Art using Python.py: -------------------------------------------------------------------------------- 1 | # pip install pyfiglet 2 | 3 | import pyfiglet 4 | font = pyfiglet.figlet_format('Coding Hubs') 5 | print(font) -------------------------------------------------------------------------------- /Create a Quiz Game.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)) -------------------------------------------------------------------------------- /Create an Invoice.py: -------------------------------------------------------------------------------- 1 | # create a product and price for three items 2 | product1_name, product1_price = 'Books', 50.95 3 | product2_name, product2_price = 'Computer', 598.99 4 | product3_name, product3_price = 'Monitor', 156.89 5 | 6 | # create a company name and information 7 | company_name = 'Thecleverprogrammer, inc.' 8 | company_address = '144 Kalka ji.' 9 | company_city = 'New Delhi' 10 | 11 | # declare ending message 12 | message = 'Thanks for shopping with us today!' 13 | 14 | # create a top border 15 | print('*' * 50) 16 | 17 | # print company information first using format 18 | print('\t\t{}'.format(company_name.title())) 19 | print('\t\t{}'.format(company_address.title())) 20 | print('\t\t{}'.format(company_city.title())) 21 | 22 | # print a line between sections 23 | print('=' * 50) 24 | 25 | # print out header for section of items 26 | print('\tProduct Name\tProduct Price') 27 | 28 | # create a print statement for each item 29 | print('\t{}\t\t${}'.format(product1_name.title(), product1_price)) 30 | print('\t{}\t${}'.format(product2_name.title(), product2_price)) 31 | print('\t{}\t\t${}'.format(product3_name.title(), product3_price)) 32 | 33 | # print a line between sections 34 | print('=' * 50) 35 | 36 | # print out header for section of total 37 | print('\t\t\tTotal') 38 | 39 | # calculate total price and print out 40 | total = product1_price + product2_price + product3_price 41 | print('\t\t\t${}'.format(total)) 42 | 43 | # print a line between sections 44 | print('=' * 50) 45 | 46 | # output thank you message 47 | print('\n\t{}\n'.format(message)) 48 | 49 | # create a bottom border 50 | print('*' * 50) -------------------------------------------------------------------------------- /Defang IP Address using Python.py: -------------------------------------------------------------------------------- 1 | 2 | def ip_address(address): 3 | new_address = "" 4 | split_address = address.split(".") 5 | separator = "[.]" 6 | new_address = separator.join(split_address) 7 | return new_address 8 | ipaddress = ip_address("1.1.2.3") 9 | print(ipaddress) -------------------------------------------------------------------------------- /Dice Roll Simulator with Python.py: -------------------------------------------------------------------------------- 1 | 2 | #importing module for random number generation 3 | import random 4 | 5 | #range of the values of a dice 6 | min_val = 1 7 | max_val = 6 8 | 9 | #to loop the rolling through user input 10 | roll_again = "yes" 11 | 12 | #loop 13 | while roll_again == "yes" or roll_again == "y": 14 | print("Rolling The Dices...") 15 | print("The Values are :") 16 | 17 | #generating and printing 1st random integer from 1 to 6 18 | print(random.randint(min_val, max_val)) 19 | 20 | #generating and printing 2nd random integer from 1 to 6 21 | print(random.randint(min_val, max_val)) 22 | 23 | #asking user to roll the dice again. Any input other than yes or y will terminate the loop 24 | roll_again = input("Roll the Dices Again?") -------------------------------------------------------------------------------- /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() -------------------------------------------------------------------------------- /Digital clock using Python.py: -------------------------------------------------------------------------------- 1 | import time 2 | import datetime as dt 3 | import turtle 4 | 5 | 6 | # create a turtle to display time 7 | t = turtle.Turtle() 8 | 9 | # create a turtle to create rectangle box 10 | t1 = turtle.Turtle() 11 | 12 | # create screen 13 | s = turtle.Screen() 14 | 15 | # set background color of the screen 16 | s.bgcolor("white") 17 | 18 | # obtain current hour, minute and second 19 | # from the system 20 | sec = dt.datetime.now().second 21 | min = dt.datetime.now().minute 22 | hr = dt.datetime.now().hour 23 | t1.pensize(3) 24 | t1.color('black') 25 | t1.penup() 26 | 27 | # set the position of turtle 28 | t1.goto(-20, 0) 29 | t1.pendown() 30 | 31 | # create rectangular box 32 | for i in range(2): 33 | t1.forward(200) 34 | t1.left(90) 35 | t1.forward(70) 36 | t1.left(90) 37 | 38 | # hide the turtle 39 | t1.hideturtle() 40 | 41 | while True: 42 | t.hideturtle() 43 | t.clear() 44 | # display the time 45 | t.write(str(hr).zfill(2) 46 | +":"+str(min).zfill(2)+":" 47 | +str(sec).zfill(2), 48 | font =("Arial Narrow", 35, "bold")) 49 | time.sleep(1) 50 | sec+= 1 51 | 52 | if sec == 60: 53 | sec = 0 54 | min+= 1 55 | 56 | if min == 60: 57 | min = 0 58 | hr+= 1 59 | 60 | if hr == 13: 61 | hr = 1 62 | -------------------------------------------------------------------------------- /Fidget Spinner Game.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() -------------------------------------------------------------------------------- /Game of Life with Python.py: -------------------------------------------------------------------------------- 1 | class game_of_life: 2 | def gameOfLife(self, board: List[List[int]]) -> None: 3 | """ 4 | Do not return anything, modify board in-place instead. 5 | """ 6 | 7 | # Neighbors array to find 8 neighboring cells for a given cell 8 | neighbors = [(1,0), (1,-1), (0,-1), (-1,-1), (-1,0), (-1,1), (0,1), (1,1)] 9 | 10 | rows = len(board) 11 | cols = len(board[0]) 12 | 13 | # Create a copy of the original board 14 | copy_board = [[board[row][col] for col in range(cols)] for row in range(rows)] 15 | 16 | # Iterate through board cell by cell. 17 | for row in range(rows): 18 | for col in range(cols): 19 | 20 | # For each cell count the number of live neighbors. 21 | live_neighbors = 0 22 | for neighbor in neighbors: 23 | 24 | r = (row + neighbor[0]) 25 | c = (col + neighbor[1]) 26 | 27 | # Check the validity of the neighboring cell and if it was originally a live cell. 28 | # The evaluation is done against the copy, since that is never updated. 29 | if (r < rows and r >= 0) and (c < cols and c >= 0) and (copy_board[r][c] == 1): 30 | live_neighbors += 1 31 | 32 | # Rule 1 or Rule 3 33 | if copy_board[row][col] == 1 and (live_neighbors < 2 or live_neighbors > 3): 34 | board[row][col] = 0 35 | # Rule 4 36 | if copy_board[row][col] == 0 and live_neighbors == 3: 37 | board[row][col] = 1 -------------------------------------------------------------------------------- /Get Live Covid-19 Data.py: -------------------------------------------------------------------------------- 1 | import csv 2 | from urllib.request import urlopen 3 | from bs4 import BeautifulSoup 4 | 5 | html = urlopen("https://bit.ly/3jpMFRW") 6 | soup = BeautifulSoup(html, "html.parser") 7 | table = soup.findAll("table", {"class":"wikitable"})[0] 8 | rows = table.findAll("tr") 9 | 10 | with open("Dataset.csv", "wt+", newline="") as f: 11 | writer = csv.writer(f) 12 | for i in rows: 13 | row = [] 14 | for cell in i.findAll(["td", "th"]): 15 | row.append(cell.get_text()) 16 | writer.writerow(row) 17 | import pandas as pd 18 | data = pd.read_csv("Dataset.csv") 19 | data.head() -------------------------------------------------------------------------------- /Indian Flag using Python.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | from turtle import* 3 | 4 | #screen for output 5 | screen = turtle.Screen() 6 | 7 | # Defining a turtle Instance 8 | t = turtle.Turtle() 9 | speed(0) 10 | 11 | # initially penup() 12 | t.penup() 13 | t.goto(-400, 250) 14 | t.pendown() 15 | 16 | # Orange Rectangle 17 | #white rectangle 18 | t.color("orange") 19 | t.begin_fill() 20 | t.forward(800) 21 | t.right(90) 22 | t.forward(167) 23 | t.right(90) 24 | t.forward(800) 25 | t.end_fill() 26 | t.left(90) 27 | t.forward(167) 28 | 29 | # Green Rectangle 30 | t.color("green") 31 | t.begin_fill() 32 | t.forward(167) 33 | t.left(90) 34 | t.forward(800) 35 | t.left(90) 36 | t.forward(167) 37 | t.end_fill() 38 | 39 | # Big Blue Circle 40 | t.penup() 41 | t.goto(70, 0) 42 | t.pendown() 43 | t.color("navy") 44 | t.begin_fill() 45 | t.circle(70) 46 | t.end_fill() 47 | 48 | # Big White Circle 49 | t.penup() 50 | t.goto(60, 0) 51 | t.pendown() 52 | t.color("white") 53 | t.begin_fill() 54 | t.circle(60) 55 | t.end_fill() 56 | 57 | # Mini Blue Circles 58 | t.penup() 59 | t.goto(-57, -8) 60 | t.pendown() 61 | t.color("navy") 62 | for i in range(24): 63 | t.begin_fill() 64 | t.circle(3) 65 | t.end_fill() 66 | t.penup() 67 | t.forward(15) 68 | t.right(15) 69 | t.pendown() 70 | 71 | # Small Blue Circle 72 | t.penup() 73 | t.goto(20, 0) 74 | t.pendown() 75 | t.begin_fill() 76 | t.circle(20) 77 | t.end_fill() 78 | # Spokes 79 | t.penup() 80 | t.goto(0, 0) 81 | t.pendown() 82 | t.pensize(2) 83 | for i in range(24): 84 | t.forward(60) 85 | t.backward(60) 86 | t.left(15) 87 | 88 | #to hold the 89 | #output window 90 | turtle.done() 91 | -------------------------------------------------------------------------------- /Internet Speed Test using Python.py: -------------------------------------------------------------------------------- 1 | #!pip install speedtest-cli 2 | 3 | import speedtest 4 | wifi = speedtest.Speedtest() 5 | print("Wifi Download Speed is ", wifi.download()) 6 | print("Wifi Upload Speed is ", wifi.upload()) -------------------------------------------------------------------------------- /LCM using Python.py: -------------------------------------------------------------------------------- 1 | 2 | def least_common_multiple(a, b): 3 | if a > b: 4 | greater = a 5 | elif b > a: 6 | greater = b 7 | while(True): 8 | if ((greater % a == 0) and (greater % b == 0)): 9 | lcm = greater 10 | break 11 | greater = greater + 1 12 | return lcm 13 | 14 | print(least_common_multiple(10, 15)) -------------------------------------------------------------------------------- /Live Weather Updates.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | import requests 3 | headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} 4 | 5 | def weather(city): 6 | city=city.replace(" ","+") 7 | res = requests.get(f'https://www.google.com/search?q={city}&oq={city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8',headers=headers) 8 | print("Searching......\n") 9 | soup = BeautifulSoup(res.text,'html.parser') 10 | location = soup.select('#wob_loc')[0].getText().strip() 11 | time = soup.select('#wob_dts')[0].getText().strip() 12 | info = soup.select('#wob_dc')[0].getText().strip() 13 | weather = soup.select('#wob_tm')[0].getText().strip() 14 | print(location) 15 | print(time) 16 | print(info) 17 | print(weather+"°C") 18 | 19 | city=input("Enter the Name of Any City >> ") 20 | city=city+" weather" 21 | weather(city) -------------------------------------------------------------------------------- /Merge Sort using Python.py: -------------------------------------------------------------------------------- 1 | def merge(listA, listB): 2 | newlist = list() 3 | a = 0 4 | b = 0 5 | while a < len(listA) and b < len(listB): 6 | if listA[a] < listB[b]: 7 | newlist.append(listA[a]) 8 | a += 1 9 | else: 10 | newlist.append(listB[b]) 11 | b += 1 12 | while a < len(listA): 13 | newlist.append(listA[a]) 14 | a += 1 15 | while b < len(listB): 16 | newlist.append(listB[b]) 17 | b += 1 18 | return newlist 19 | 20 | def merge_sort(input_list): 21 | if len(input_list) <= 1: 22 | return input_list 23 | else: 24 | mid = len(input_list) // 2 25 | left = merge_sort(input_list[:mid]) 26 | right = merge_sort(input_list[mid:]) 27 | newlist = merge(left, right) 28 | return newlist 29 | 30 | a = [56, 89, 45, 34, 90, 32, 20, 67, 43] 31 | print(merge_sort(a)) -------------------------------------------------------------------------------- /Monty Hall Simulator.py: -------------------------------------------------------------------------------- 1 | import random 2 | from random import seed, randint 3 | import numpy 4 | 5 | def game(winningdoor, selecteddoor, change=False): 6 | assert winningdoor < 3 7 | assert winningdoor >= 0 8 | 9 | # Presenter removes the first door that was not selected neither winning 10 | removeddoor = next(i for i in range(3) if i != selecteddoor and i != winningdoor) 11 | 12 | # Player decides to change its choice 13 | if change: 14 | selecteddoor = next(i for i in range(3) if i != selecteddoor and i != removeddoor) 15 | 16 | # We suppose the player never wants to change its initial choice. 17 | return selecteddoor == winningdoor 18 | 19 | 20 | if __name__ == '__main__': 21 | playerdoors = numpy.random.random_integers(0,2, (1000 * 1000 * 1,)) 22 | 23 | winningdoors = [d for d in playerdoors if game(1, d)] 24 | print("Winning percentage without changing choice: ", len(winningdoors) / len(playerdoors)) 25 | 26 | winningdoors = [d for d in playerdoors if game(1, d, change=True)] 27 | print("Winning percentage while changing choice: ", len(winningdoors) / len(playerdoors)) -------------------------------------------------------------------------------- /Music Player GUI.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 | 21 | def play(): 22 | pygame.mixer.music.load(play_list.get(tkr.ACTIVE)) 23 | var.set(play_list.get(tkr.ACTIVE)) 24 | pygame.mixer.music.play() 25 | def stop(): 26 | pygame.mixer.music.stop() 27 | def pause(): 28 | pygame.mixer.music.pause() 29 | def unpause(): 30 | pygame.mixer.music.unpause() 31 | Button1 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="PLAY", command=play, bg="blue", fg="white") 32 | Button2 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="STOP", command=stop, bg="red", fg="white") 33 | Button3 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="PAUSE", command=pause, bg="purple", fg="white") 34 | Button4 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="UNPAUSE", command=unpause, bg="orange", fg="white") 35 | 36 | var = tkr.StringVar() 37 | song_title = tkr.Label(music_player, font="Helvetica 12 bold", textvariable=var) 38 | 39 | song_title.pack() 40 | Button1.pack(fill="x") 41 | Button2.pack(fill="x") 42 | Button3.pack(fill="x") 43 | Button4.pack(fill="x") 44 | play_list.pack(fill="both", expand="yes") 45 | music_player.mainloop() -------------------------------------------------------------------------------- /Number Guessing Game with Python.py: -------------------------------------------------------------------------------- 1 | # to import random module 2 | import random 3 | # to create a range of random numbers between 1-10 4 | n = random.randrange(1,100) 5 | # to take a user input to enter a number 6 | guess = int(input("Enter any number: ")) 7 | while n!= guess: # means if n is not equal to the input guess 8 | # if guess is smaller than n 9 | if guess < n: 10 | print("Too low") 11 | # to again ask for input 12 | guess = int(input("Enter number again: ")) 13 | # if guess is greater than n 14 | elif guess > n: 15 | print("Too high!") 16 | # to again ask for the user input 17 | guess = int(input("Enter number again: ")) 18 | # if guess gets equals to n terminate the while loop 19 | else: 20 | break 21 | print("you guessed it right!!") -------------------------------------------------------------------------------- /Password Authentication using Python.py: -------------------------------------------------------------------------------- 1 | import getpass 2 | database = {"aman.kharwal": "123456", "kharwal.aman": "654321"} 3 | username = input("Enter Your Username : ") 4 | password = getpass.getpass("Enter Your Password : ") 5 | for i in database.keys(): 6 | if username == i: 7 | while password != database.get(i): 8 | password = getpass.getpass("Enter Your Password Again : ") 9 | break 10 | print("Verified") -------------------------------------------------------------------------------- /Pencil Sketch.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | image = cv2.imread("image.jpg") 4 | cv2.imshow("Dog", image) 5 | cv2.waitKey(0) 6 | 7 | gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 8 | cv2.imshow("New Dog", gray_image) 9 | cv2.waitKey(0) 10 | 11 | inverted_image = 255 - gray_image 12 | cv2.imshow("Inverted", inverted_image) 13 | cv2.waitKey() 14 | 15 | blurred = cv2.GaussianBlur(inverted_image, (21, 21), 0) 16 | 17 | inverted_blurred = 255 - blurred 18 | pencil_sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0) 19 | cv2.imshow("Sketch", pencil_sketch) 20 | cv2.waitKey(0) 21 | 22 | cv2.imshow("original image", image) 23 | cv2.imshow("pencil sketch", pencil_sketch) 24 | cv2.waitKey(0) 25 | 26 | -------------------------------------------------------------------------------- /Pick a Random Card.py: -------------------------------------------------------------------------------- 1 | import random 2 | cards = ["Diamonds", "Spades", "Hearts", "Clubs"] 3 | ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King", "Ace"] 4 | 5 | def pick_a_card(): 6 | card = random.choices(cards) 7 | rank = random.choices(ranks) 8 | return(f"The {rank} of {card}") 9 | 10 | print(pick_a_card()) -------------------------------------------------------------------------------- /Print a Calendar using Python.py: -------------------------------------------------------------------------------- 1 | import calendar 2 | print(calendar.month(2022, 6)) 3 | -------------------------------------------------------------------------------- /Pyramid Pattern.py: -------------------------------------------------------------------------------- 1 | 2 | def pyramid_pattern(n): 3 | a = 2 * n-2 4 | for i in range(0, n): 5 | for j in range(0, a): 6 | print(end=" ") 7 | a = a-1 8 | for j in range(0, i+1): 9 | print("*", end=" ") 10 | print("\r") 11 | print(pyramid_pattern(10)) -------------------------------------------------------------------------------- /Python Program to Count Most Frequent Words in a File.py: -------------------------------------------------------------------------------- 1 | words = [] 2 | with open("file.txt", "r") as f: 3 | for line in f: 4 | words.extend(line.split()) 5 | 6 | from collections import Counter 7 | counts = Counter(words) 8 | top5 = counts.most_common(5) 9 | print(top5) -------------------------------------------------------------------------------- /Python Program to Generate Password.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) -------------------------------------------------------------------------------- /QR Code using Python.py: -------------------------------------------------------------------------------- 1 | # Install these modules 2 | # pip install PyQRCode 3 | # pip install pypng 4 | 5 | import pyqrcode 6 | import png 7 | link = "https://www.instagram.com/coding.hubs/" 8 | qr_code = pyqrcode.create(link) 9 | qr_code.png("instagram.png", scale=5) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Basic Python-Projects -------------------------------------------------------------------------------- /Real-time Currency Converter.py: -------------------------------------------------------------------------------- 1 | from forex_python.converter import CurrencyRates 2 | c = CurrencyRates() 3 | amount = int(input("Enter the amount: ")) 4 | from_currency = input("From Currency: ").upper() 5 | to_currency = input("To Currency: ").upper() 6 | print(from_currency, " To ", to_currency, amount) 7 | result = c.convert(from_currency, to_currency, amount) 8 | print(result) -------------------------------------------------------------------------------- /Resume Scanner.py: -------------------------------------------------------------------------------- 1 | def scan_resume(resume): 2 | from resume_parser import resumeparse 3 | data = resumeparse.read_file(resume) 4 | for i, j in data.items(): 5 | print(f"{i}:>>{j}") 6 | 7 | scan_resume("Aman Kharwal.docx") -------------------------------------------------------------------------------- /Rock Paper and Scissors 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 -------------------------------------------------------------------------------- /Screen Pet.py: -------------------------------------------------------------------------------- 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 | c = Canvas(root, width=400, height=400) 73 | c.configure(bg='dark blue', highlightthickness=0) 74 | c.body_color = 'SkyBlue1' 75 | 76 | body = c.create_oval(35, 20, 365, 350, outline=c.body_color, fill=c.body_color) 77 | ear_left = c.create_polygon(75, 80, 75, 10, 165, 70, outline=c.body_color, fill=c.body_color) 78 | ear_right = c.create_polygon(255, 45, 325, 10, 320, 70, outline=c.body_color, fill=c.body_color) 79 | foot_left = c.create_oval(65, 320, 145, 360, outline=c.body_color, fill=c.body_color) 80 | foot_right = c.create_oval(250, 320, 330, 360, outline=c.body_color, fill=c.body_color) 81 | 82 | eye_left = c.create_oval(130, 110, 160, 170, outline='black', fill='white') 83 | pupil_left = c.create_oval(140, 145, 150, 155, outline='black', fill='black') 84 | eye_right = c.create_oval(230, 110, 260, 170, outline='black', fill='white') 85 | pupil_right = c.create_oval(240, 145, 250, 155, outline='black', fill='black') 86 | 87 | 88 | mouth_normal = c.create_line(170, 250, 200, 272, 230, 250, smooth=1, width=2, state=NORMAL) 89 | mouth_happy = c.create_line(170, 250, 200, 282, 230, 250, smooth=1, width=2, state=HIDDEN) 90 | mouth_sad = c.create_line(170, 250, 200, 232, 230, 250, smooth=1, width=2, state=HIDDEN) 91 | tongue_main = c.create_rectangle(170, 250, 230, 290, outline='red', fill='red', state=HIDDEN) 92 | tongue_tip = c.create_oval(170, 285, 230, 300, outline='red', fill='red', state=HIDDEN) 93 | 94 | cheek_left = c.create_oval(70, 180, 120, 230, outline='pink', fill='pink', state=HIDDEN) 95 | cheek_right = c.create_oval(280, 180, 330, 230, outline='pink', fill='pink', state=HIDDEN) 96 | 97 | c.pack() 98 | c.bind('', show_happy) 99 | c.bind('', hide_happy) 100 | c.bind('', cheeky) 101 | 102 | c.happy_level = 10 103 | c.eyes_crossed = False 104 | c.tongue_out = False 105 | 106 | root.after(1000, blink) 107 | root.after(5000, sad) 108 | root.mainloop() -------------------------------------------------------------------------------- /Send Automatic Emails.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | import smtplib 4 | 5 | 6 | def automatic_email(): 7 | user = input("Enter Your Name >>: ") 8 | email = input("Enter Your Email >>: ") 9 | message = (f"Dear {user}, Welcome") 10 | s = smtplib.SMTP('smtp.gmail.com', 587) 11 | s.starttls() 12 | s.login("Your Gmail Account", "Your App Password") 13 | s.sendmail('&&&&&&&&&&&', email, message) 14 | print("Email Sent!") 15 | 16 | automatic_email() -------------------------------------------------------------------------------- /Send Instagram Messages using Python.py: -------------------------------------------------------------------------------- 1 | # pip install instabot 2 | 3 | from instabot import Bot 4 | bot = Bot() 5 | 6 | bot.login(username="Your Username", password="Your Password") 7 | bot.send_message("Hi Brother", ["Receiver's Username"]) -------------------------------------------------------------------------------- /Shutdown Computer using Python.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | def shutdown_PC(): 4 | os.system("shutdown /s /t 1") 5 | shutdown_PC() -------------------------------------------------------------------------------- /Snake Game with Python.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | import random 3 | 4 | w = 500 5 | h = 500 6 | fs = 10 7 | d = 100 # milliseconds 8 | 9 | offsets = { 10 | "up": (0, 20), 11 | "down": (0, -20), 12 | "left": (-20, 0), 13 | "right": (20, 0) 14 | } 15 | 16 | def r(): 17 | global saap, kata, khanaT, pen 18 | saap = [[0, 0], [0, 20], [0, 40], [0, 60], [0, 80]] 19 | kata = "up" 20 | khanaT = nun() 21 | food.goto(khanaT) 22 | hall() 23 | 24 | def hall(): 25 | global kata 26 | 27 | new_head = saap[-1].copy() 28 | new_head[0] = saap[-1][0] + offsets[kata][0] 29 | new_head[1] = saap[-1][1] + offsets[kata][1] 30 | 31 | if new_head in saap[:-1]: 32 | r() 33 | else: 34 | saap.append(new_head) 35 | 36 | if not khana(): 37 | saap.pop(0) 38 | 39 | if saap[-1][0] > w / 2: 40 | saap[-1][0] -= w 41 | elif saap[-1][0] < - w / 2: 42 | saap[-1][0] += w 43 | elif saap[-1][1] > h / 2: 44 | saap[-1][1] -= h 45 | elif saap[-1][1] < -h / 2: 46 | saap[-1][1] += h 47 | 48 | pen.clearstamps() 49 | #clears all the stamps 50 | 51 | for segment in saap: 52 | pen.goto(segment[0], segment[1]) 53 | pen.stamp() 54 | 55 | screen.update() 56 | #updates the turtle.screen screen 57 | 58 | turtle.ontimer(hall, d) 59 | 60 | def khana(): 61 | global khanaT 62 | if dist(saap[-1], khanaT) < 20: 63 | khanaT = nun() 64 | food.goto(khanaT) 65 | return True 66 | return False 67 | 68 | def nun(): 69 | x = random.randint(- w / 2 + fs, w / 2 - fs) 70 | y = random.randint(- h / 2 + fs, h / 2 - fs) 71 | return (x, y) 72 | 73 | def dist(poos1, poos2): 74 | x1, y1 = poos1 75 | x2, y2 = poos2 76 | distance = ((y2 - y1) ** 2 + (x2 - x1) ** 2) ** 0.5 77 | return distance 78 | 79 | def mathi(): 80 | global kata 81 | if kata != "down": 82 | kata = "up" 83 | 84 | def go_right(): 85 | global kata 86 | if kata != "left": 87 | kata = "right" 88 | 89 | def go_down(): 90 | global kata 91 | if kata != "up": 92 | kata = "down" 93 | 94 | def go_left(): 95 | global kata 96 | if kata != "right": 97 | kata = "left" 98 | 99 | screen = turtle.Screen() 100 | screen.setup(w, h) 101 | screen.title("saap") 102 | screen.bgcolor("green") 103 | screen.setup(500, 500) 104 | screen.tracer(0) 105 | 106 | pen = turtle.Turtle("square") 107 | pen.penup() 108 | 109 | food = turtle.Turtle() 110 | food.shape("circle") 111 | food.color("white") 112 | food.shapesize(fs / 20) 113 | food.penup() 114 | 115 | screen.listen() 116 | screen.onkey(mathi, "Up") 117 | screen.onkey(go_right, "Right") 118 | screen.onkey(go_down, "Down") 119 | screen.onkey(go_left, "Left") 120 | 121 | r() 122 | turtle.done() -------------------------------------------------------------------------------- /Sorting_Visualizer.py: -------------------------------------------------------------------------------- 1 | # Python implementation for visualizing merge sort. 2 | import pygame 3 | import random 4 | 5 | pygame.font.init() 6 | # Total window 7 | screen = pygame.display.set_mode((900, 650)) 8 | 9 | # Title and Icon 10 | pygame.display.set_caption("SORTING VISUALISER") 11 | 12 | # Boolean variable to run the program in while loop 13 | run = True 14 | 15 | # Window size 16 | width = 900 17 | length = 600 18 | array = [0] * 151 19 | arr_clr = [(0, 255, 255)] * 151 20 | clr_ind = 0 21 | clr = [(0, 204, 204), (255, 0, 0), 22 | (0, 0, 153), (255, 102, 0)] 23 | fnt = pygame.font.SysFont("comicsans", 30) 24 | fnt1 = pygame.font.SysFont("comicsans", 20) 25 | 26 | 27 | # Generate new Array 28 | def generate_arr(): 29 | for i in range(1, 151): 30 | arr_clr[i] = clr[0] 31 | array[i] = random.randrange(1, 100) 32 | 33 | 34 | generate_arr() 35 | 36 | 37 | def refill(): 38 | screen.fill((255, 255, 255)) 39 | draw() 40 | pygame.display.update() 41 | pygame.time.delay(20) 42 | 43 | 44 | # Sorting Algo:Merge sort 45 | def mergesort(array, l, r): 46 | mid = (l + r) // 2 47 | if l < r: 48 | mergesort(array, l, mid) 49 | mergesort(array, mid + 1, r) 50 | merge(array, l, mid, 51 | mid + 1, r) 52 | 53 | 54 | def merge(array, x1, y1, x2, y2): 55 | i = x1 56 | j = x2 57 | temp = [] 58 | pygame.event.pump() 59 | while i <= y1 and j <= y2: 60 | arr_clr[i] = clr[1] 61 | arr_clr[j] = clr[1] 62 | refill() 63 | arr_clr[i] = clr[0] 64 | arr_clr[j] = clr[0] 65 | if array[i] < array[j]: 66 | temp.append(array[i]) 67 | i += 1 68 | else: 69 | temp.append(array[j]) 70 | j += 1 71 | while i <= y1: 72 | arr_clr[i] = clr[1] 73 | refill() 74 | arr_clr[i] = clr[0] 75 | temp.append(array[i]) 76 | i += 1 77 | while j <= y2: 78 | arr_clr[j] = clr[1] 79 | refill() 80 | arr_clr[j] = clr[0] 81 | temp.append(array[j]) 82 | j += 1 83 | j = 0 84 | for i in range(x1, y2 + 1): 85 | pygame.event.pump() 86 | array[i] = temp[j] 87 | j += 1 88 | arr_clr[i] = clr[2] 89 | refill() 90 | if y2 - x1 == len(array) - 2: 91 | arr_clr[i] = clr[3] 92 | else: 93 | arr_clr[i] = clr[0] 94 | 95 | 96 | # Draw the array values 97 | def draw(): 98 | # Text should be rendered 99 | txt = fnt.render("PRESS" \ 100 | " 'ENTER' TO PERFORM SORTING.", 1, (0, 0, 0)) 101 | # Position where text is placed 102 | screen.blit(txt, (20, 20)) 103 | txt1 = fnt.render("PRESS 'R' FOR NEW ARRAY.", 104 | 1, (0, 0, 0)) 105 | screen.blit(txt1, (20, 40)) 106 | txt2 = fnt1.render("ALGORITHM USED: " \ 107 | "MERGE SORT", 1, (0, 0, 0)) 108 | screen.blit(txt2, (600, 60)) 109 | element_width = (width - 150) // 150 110 | boundry_arr = 900 / 150 111 | boundry_grp = 550 / 100 112 | pygame.draw.line(screen, (0, 0, 0), 113 | (0, 95), (900, 95), 6) 114 | for i in range(1, 100): 115 | pygame.draw.line(screen, 116 | (224, 224, 224), 117 | (0, boundry_grp * i + 100), 118 | (900, boundry_grp * i + 100), 1) 119 | 120 | # Drawing the array values as lines 121 | for i in range(1, 151): 122 | pygame.draw.line(screen, arr_clr[i], \ 123 | (boundry_arr * i - 3, 100), \ 124 | (boundry_arr * i - 3, array[i] * boundry_grp + 100), \ 125 | element_width) 126 | 127 | 128 | # Infinite loop to keep the window open 129 | while run: 130 | # background 131 | screen.fill((255, 255, 255)) 132 | # Event handler stores all event 133 | for event in pygame.event.get(): 134 | # If we click Close button in window 135 | if event.type == pygame.QUIT: 136 | run = False 137 | if event.type == pygame.KEYDOWN: 138 | if event.key == pygame.K_r: 139 | generate_arr() 140 | if event.key == pygame.K_RETURN: 141 | mergesort(array, 1, len(array) - 1) 142 | draw() 143 | pygame.display.update() 144 | 145 | pygame.quit() 146 | -------------------------------------------------------------------------------- /Text to Handwriting using Python.py: -------------------------------------------------------------------------------- 1 | import pywhatkit as kit 2 | import cv2 3 | 4 | kit.text_to_handwriting("Hope you are doing well, Maaandu", save_to="C:/Users/pc/Pictures/RESULTS/handwriting.png") 5 | img = cv2.imread("handwriting.png") 6 | cv2.imshow("Text to Handwriting", img) 7 | cv2.waitKey(0) 8 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Treemap using Python.py: -------------------------------------------------------------------------------- 1 | import plotly.graph_objects as go 2 | 3 | fig = go.Figure(go.Treemap( 4 | labels = ["A","B", "C", "D", "E", "F", "G", "H", "I"], 5 | parents = ["", "A", "A", "C", "C", "A", "A", "G", "A"] 6 | )) 7 | 8 | fig.show() 9 | -------------------------------------------------------------------------------- /URL Shortener.py: -------------------------------------------------------------------------------- 1 | from __future__ import with_statement 2 | import contextlib 3 | try: 4 | from urllib.parse import urlencode 5 | except ImportError: 6 | from urllib import urlencode 7 | try: 8 | from urllib.request import urlopen 9 | except ImportError: 10 | from urllib2 import urlopen 11 | import sys 12 | 13 | def make_tiny(url): 14 | request_url = ('http://tinyurl.com/api-create.php?' + 15 | urlencode({'url':url})) 16 | with contextlib.closing(urlopen(request_url)) as response: 17 | return response.read().decode('utf-8') 18 | 19 | def main(): 20 | for tinyurl in map(make_tiny, sys.argv[1:]): 21 | print(tinyurl) 22 | 23 | if __name__ == '__main__': 24 | main() -------------------------------------------------------------------------------- /Video to Audio Converter.py: -------------------------------------------------------------------------------- 1 | 2 | from pytube import YouTube 3 | import pytube 4 | import os 5 | 6 | def main(): 7 | video_url = input('Enter YouTube video URL: ') 8 | 9 | if os.name == 'nt': 10 | path = os.getcwd() + '\\' 11 | else: 12 | path = os.getcwd() + '/' 13 | 14 | name = pytube.extract.video_id(video_url) 15 | YouTube(video_url).streams.filter(only_audio=True).first().download(filename=name) 16 | location = path + name + '.mp4' 17 | renametomp3 = path + name + '.mp3' 18 | 19 | if os.name == 'nt': 20 | os.system('ren {0} {1}'. format(location, renametomp3)) 21 | else: 22 | os.system('mv {0} {1}'. format(location, renametomp3)) 23 | 24 | if __name__ == '__main__': 25 | main() -------------------------------------------------------------------------------- /Voice Recorder using Python.py: -------------------------------------------------------------------------------- 1 | import sounddevice 2 | from scipy.io.wavfile import write 3 | 4 | def voice_recorder(seconds, file): 5 | print("Recording Started…") 6 | recording = sounddevice.rec((seconds * 44100), samplerate= 44100, channels=2) 7 | sounddevice.wait() 8 | write(file, 44100, recording) 9 | print("Recording Finished") 10 | 11 | voice_recorder(10, "record.wav") -------------------------------------------------------------------------------- /Web Scraping to Create a Dataset using Python.py: -------------------------------------------------------------------------------- 1 | import csv 2 | from urllib.request import urlopen 3 | from bs4 import BeautifulSoup 4 | 5 | html = urlopen("https://en.wikipedia.org/wiki/Comparison_of_programming_languages") 6 | soup = BeautifulSoup(html, "html.parser") 7 | table = soup.findAll("table", {"class":"wikitable"})[0] 8 | rows = table.findAll("tr") 9 | 10 | with open("language.csv", "wt+", newline="") as f: 11 | writer = csv.writer(f) 12 | for i in rows: 13 | row = [] 14 | for cell in i.findAll(["td", "th"]): 15 | row.append(cell.get_text()) 16 | writer.writerow(row) 17 | 18 | 19 | import pandas as pd 20 | a = pd.read_csv("language.csv") 21 | a.head() -------------------------------------------------------------------------------- /Wifi password using python.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | 3 | data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n') 4 | profiles = [i.split(":")[1][1:-1] for i in data if "All User Profile" in i] 5 | for i in profiles: 6 | results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8').split('\n') 7 | results = [b.split(":")[1][1:-1] for b in results if "Key Content" in b] 8 | try: 9 | print ("{:<30}| {:<}".format(i, results[0])) 10 | except IndexError: 11 | print ("{:<30}| {:<}".format(i, "")) 12 | input("") -------------------------------------------------------------------------------- /currency-converter-project.py: -------------------------------------------------------------------------------- 1 | # # Python Project on Currency Converter 2 | 3 | import requests 4 | from tkinter import * 5 | import tkinter as tk 6 | from tkinter import ttk 7 | 8 | 9 | class RealTimeCurrencyConverter(): 10 | def __init__(self,url): 11 | self.data = requests.get(url).json() 12 | self.currencies = self.data['rates'] 13 | 14 | def convert(self, from_currency, to_currency, amount): 15 | initial_amount = amount 16 | if from_currency != 'USD' : 17 | amount = amount / self.currencies[from_currency] 18 | 19 | # limiting the precision to 4 decimal places 20 | amount = round(amount * self.currencies[to_currency], 4) 21 | return amount 22 | 23 | class App(tk.Tk): 24 | 25 | def __init__(self, converter): 26 | tk.Tk.__init__(self) 27 | self.title = 'Currency Converter' 28 | self.currency_converter = converter 29 | 30 | #self.configure(background = 'blue') 31 | self.geometry("500x200") 32 | 33 | # Label 34 | self.intro_label = Label(self, text = 'Welcome to Real Time Currency Convertor', fg = 'blue', relief = tk.RAISED, borderwidth = 3) 35 | self.intro_label.config(font = ('Courier',15,'bold')) 36 | 37 | self.date_label = Label(self, text = f"1 Indian Rupee equals = {self.currency_converter.convert('INR','USD',1)} USD \n Date : {self.currency_converter.data['date']}", relief = tk.GROOVE, borderwidth = 5) 38 | 39 | self.intro_label.place(x = 10 , y = 5) 40 | self.date_label.place(x = 160, y= 50) 41 | 42 | # Entry box 43 | valid = (self.register(self.restrictNumberOnly), '%d', '%P') 44 | self.amount_field = Entry(self,bd = 3, relief = tk.RIDGE, justify = tk.CENTER,validate='key', validatecommand=valid) 45 | self.converted_amount_field_label = Label(self, text = '', fg = 'black', bg = 'white', relief = tk.RIDGE, justify = tk.CENTER, width = 17, borderwidth = 3) 46 | 47 | # dropdown 48 | self.from_currency_variable = StringVar(self) 49 | self.from_currency_variable.set("INR") # default value 50 | self.to_currency_variable = StringVar(self) 51 | self.to_currency_variable.set("USD") # default value 52 | 53 | font = ("Courier", 12, "bold") 54 | self.option_add('*TCombobox*Listbox.font', font) 55 | self.from_currency_dropdown = ttk.Combobox(self, textvariable=self.from_currency_variable,values=list(self.currency_converter.currencies.keys()), font = font, state = 'readonly', width = 12, justify = tk.CENTER) 56 | self.to_currency_dropdown = ttk.Combobox(self, textvariable=self.to_currency_variable,values=list(self.currency_converter.currencies.keys()), font = font, state = 'readonly', width = 12, justify = tk.CENTER) 57 | 58 | # placing 59 | self.from_currency_dropdown.place(x = 30, y= 120) 60 | self.amount_field.place(x = 36, y = 150) 61 | self.to_currency_dropdown.place(x = 340, y= 120) 62 | #self.converted_amount_field.place(x = 346, y = 150) 63 | self.converted_amount_field_label.place(x = 346, y = 150) 64 | 65 | # Convert button 66 | self.convert_button = Button(self, text = "Convert", fg = "black", command = self.perform) 67 | self.convert_button.config(font=('Courier', 10, 'bold')) 68 | self.convert_button.place(x = 225, y = 135) 69 | 70 | def perform(self): 71 | amount = float(self.amount_field.get()) 72 | from_curr = self.from_currency_variable.get() 73 | to_curr = self.to_currency_variable.get() 74 | 75 | converted_amount = self.currency_converter.convert(from_curr,to_curr,amount) 76 | converted_amount = round(converted_amount, 2) 77 | 78 | self.converted_amount_field_label.config(text = str(converted_amount)) 79 | 80 | def restrictNumberOnly(self, action, string): 81 | regex = re.compile(r"[0-9,]*?(\.)?[0-9,]*$") 82 | result = regex.match(string) 83 | return (string == "" or (string.count('.') <= 1 and result is not None)) 84 | 85 | if __name__ == '__main__': 86 | url = 'https://api.exchangerate-api.com/v4/latest/USD' 87 | converter = RealTimeCurrencyConverter(url) 88 | 89 | App(converter) 90 | mainloop() 91 | 92 | -------------------------------------------------------------------------------- /passwordgenerator.py: -------------------------------------------------------------------------------- 1 | #importing Libraries 2 | 3 | from tkinter import * 4 | import random, string 5 | import pyperclip 6 | 7 | 8 | 9 | ###initialize window 10 | 11 | root =Tk() 12 | root.geometry("400x400") 13 | root.resizable(0,0) 14 | root.title("CodingHubs - PASSWORD GENERATOR") 15 | 16 | #heading 17 | heading = Label(root, text = 'PASSWORD GENERATOR' , font ='arial 15 bold').pack() 18 | Label(root, text ='CodingHubs', font ='arial 15 bold').pack(side = BOTTOM) 19 | 20 | 21 | 22 | ###select password length 23 | pass_label = Label(root, text = 'PASSWORD LENGTH', font = 'arial 10 bold').pack() 24 | pass_len = IntVar() 25 | length = Spinbox(root, from_ = 8, to_ = 32 , textvariable = pass_len , width = 15).pack() 26 | 27 | 28 | 29 | #####define function 30 | 31 | pass_str = StringVar() 32 | 33 | def Generator(): 34 | password = '' 35 | for x in range (0,4): 36 | password = random.choice(string.ascii_uppercase)+random.choice(string.ascii_lowercase)+random.choice(string.digits)+random.choice(string.punctuation) 37 | for y in range(pass_len.get()- 4): 38 | password = password+random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation) 39 | pass_str.set(password) 40 | 41 | 42 | 43 | ###button 44 | 45 | Button(root, text = "GENERATE PASSWORD" , command = Generator ).pack(pady= 5) 46 | 47 | Entry(root , textvariable = pass_str).pack() 48 | 49 | ########function to copy 50 | 51 | def Copy_password(): 52 | pyperclip.copy(pass_str.get()) 53 | 54 | Button(root, text = 'COPY TO CLIPBOARD', command = Copy_password).pack(pady=5) 55 | 56 | 57 | 58 | 59 | # loop to run program 60 | root.mainloop() 61 | --------------------------------------------------------------------------------