Posts

Face Detection Script in Python

Method # 1 import cv2 #pip install opencv-python import pathlib # take the cascade file for frontal face detection cascade_path = pathlib.Path(cv2.__file__).parent.absolute()/"data/haarcascade_frontalface_default.xml" # print(cascade_path) # training classifier on the cascade file clf = cv2.CascadeClassifier(str(cascade_path)) # face detection in camera camera = cv2.VideoCapture(0) # 0 is for default camera # face detection in video # camera = cv2.VideoCapture("cud.mp4") while True: _, frame = camera.read() # _ ignores the first return value # some Python functions return multiple values, often we don’t need all of them. gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = clf.detectMultiScale( gray, scaleFactor = 1.1, minNeighbors=5, # higher this number, less faces are found minSize = (30, 30), # size of window flags = cv2.CASCADE_SCALE_IMAGE)

Implementing Real-World English Dictionary in Python

# pip install Py-Dictionary from pydictionary import Dictionary print("Welocme to the English Dictionary!") print("""What you want to know? A- Meanings B- Synonyms C- Antonyms""") option = input("Plz enter your option: ").lower() if option == "a": word = input("Enter the word to know its meaning(s): ") dict = Dictionary(word, 2) dict.print_meanings("yellow") # yellow is for color of the printed text elif option == "b": word = input("Enter the word to know its synonym(s): ") dict = Dictionary(word, 3) dict.print_synonyms("blue") elif option == "c": word = input("Enter the word to know its antonym(s): ") dict = Dictionary(word, 4) dict.print_antonyms("green") else: print("Invalid input")

Creating Custom French-to-English Dictionary in Python

dictFrench = { "je": "I", "chat": "cat", "chien": "dog", "cheval": "horse", "femme": "woman", "fille": "girl", "homme": "man", "avec": "with", "elle": "she", "garcon": "boy", "bonjour": "Good Morning!", "salut": "hi" } print("\nWelcome to the cute little French-to-English Dictionary!") print("\nThis dictionary contains the following French words.") for word in dictFrench.keys(): print(word) while True: french_word = input("\nInput any French word to know its english meaning: ") if french_word in dictFrench.keys(): print(f"\'{french_word}\' is French for \'{dictFrench[french_word]}\'.") e

Leap Year Finder in Python

# a year is leap year if it is evenly divisble by 4 # a year is leap year if it is evenly divisible by 4 but may not by 100 # a year is leap year if it is evenly divisible by 4, by 100 as well as by 400 print("Welcome to Leap Year Finder!") while True: year = int(input("Plz enter the year: ")) if year % 4 == 0: if year % 100 == 0: if year % 400 == 0: print(f"{year} is a Leap Year.") else: print(f"{year} is not a Leap Year.") else: print(f"{year} is a Leap Year.") else: print(f"{year} is not a Leap Year.")

Currency Converter from USD to PKR and vice versa in Python

print("Welcome to Currency Converter!") print("A- USD to PKR") print("B- PKR to USD") choice = input("Plz enter your choice: ").lower() if choice == "a": dollars = float(input("Plz enter the amount of dollars: ")) pkr = dollars * 261.17 print(f"{dollars} dollar(s) is equal to {round((pkr), 2)} Pakistani Rupees!") elif choice == "b": pkr = float(input("Plz enter the amount of rupees: ")) dollars = pkr / 261.17 print(f"{pkr} Rupee(s) is equal to {round((dollars), 2)} US dollars!") else: print("invalid input.")

Site Connectivity Checker Script in Python

import urllib.request as ur def site_connectivity_checker(url): print("Checking the status of the site", site_url) response = ur.urlopen(url) print("Successfully connected to", url) print("The status code of your website is",response.getcode()) print("This tool checks the status of your website") site_url = input("Plz input your website's url: ") site_connectivity_checker(site_url)

Dice Rolling Simulator Program in Python

import random dice_drawings = { 1: ("┌─────────┐", "│ │", "│ ● │", "│ │", "└─────────┘"), 2: ("┌─────────┐", "│ ● │", "│ │", "│ ● │", "└─────────┘"), 3: ("┌─────────┐", "│ ● │", "│ ● │", "│ ● │", "└─────────┘"), 4: ("┌─────────┐", "│ ● ● │", "│ │", "│ ● ● │", "└─────────┘"), 5: ("┌─────────┐", "│ ● ● │", "│ ● │", "│ ● ● │", "└─────────┘"), 6: ("┌─────────┐", "│ ● ● │", "│