#The `skimage` package comes with data built-in that
#you can run computer vision algorithms
from skimage import data, io, filters
image = data.coins()
edges = filters.sobel(image)
io.imshow( edges)
#clcoding.com
Python Coding August 16, 2022 Python No comments
# importing packages
from pytube import YouTube
import os
# url input from user
yt = YouTube(str(input("Enter the URL of the video you want to download: \n>> ")))
# extract only audio
video = yt.streams.filter(only_audio=True).first()
# check for destination to save file
print("Enter the destination (leave blank for current directory)")
destination = str(input(">> ")) or '.'
# download the file
out_file = video.download(output_path=destination)
# save the file
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file) #clcoding.com
# result of success
print(yt.title + " has been successfully downloaded in .mp3 format.")
Python Coding August 15, 2022 Python No comments
from pdf2docx import Converter
pdf_file = 'clcoding.pdf'
docx_file = 'clcoding.docx'
cv = Converter(pdf_file)
cv.convert(docx_file)
cv.close()
#clcoding.com
[INFO] Start to convert clcoding.pdf [INFO] [1/4] Opening document... [INFO] [2/4] Analyzing document... [INFO] [3/4] Parsing pages... [INFO] (1/1) Page 1 [INFO] [4/4] Creating pages... [INFO] (1/1) Page 1 [INFO] Terminated in 0.16s.
Python Coding August 15, 2022 Python No comments
INDIAN Flag in Python. All dimensions are as per our INDIAN standards. Let us know if you have any suggestions.
import numpy as np
import matplotlib.pyplot as py
import matplotlib.patches as patch
#Plotting the tri colours in national flag
a = patch.Rectangle((0,1), width=9, height=2, facecolor='#138808', edgecolor='grey')
b = patch.Rectangle((0,3), width=9, height=2, facecolor='#ffffff', edgecolor='grey')
c = patch.Rectangle((0,5), width=9, height=2, facecolor='#FF6103', edgecolor='grey')
m,n = py.subplots()
n.add_patch(a)
n.add_patch(b)
n.add_patch(c)
#AshokChakra Circle
radius=0.8
py.plot(4.5,4, marker = 'o', markerfacecolor = '#000080', markersize = 9.5)
chakra = py.Circle((4.5, 4), radius, color='#000080', fill=False, linewidth=7)
n.add_artist(chakra)
#24 spokes in AshokChakra
for i in range(0,24):
p = 4.5 + radius/2 * np.cos(np.pi*i/9 + np.pi/48)
q = 4.5 + radius/2 * np.cos(np.pi*i/9 - np.pi/48)
r = 4 + radius/2 * np.sin(np.pi*i/9 + np.pi/48)
s = 4 + radius/2 * np.sin(np.pi*i/9 - np.pi/48)
t = 4.5 + radius * np.cos(np.pi*i/9)
u = 4 + radius * np.sin(np.pi*i/9)
n.add_patch(patch.Polygon([[4.5,4], [p,r], [t,u],[q,s]], fill=True, closed=True, color='#000080'))
py.axis('equal')
py.show() #clcoding.com
Python Coding August 15, 2022 Python No comments
from zipfile import ZipFile
with ZipFile('binod.zip', 'r') as zip_object:
zip_object.extractall()
#list of files that are archived in the ZIP file
print(zip_object.namelist())
#clcoding.com
['binod.jpg', 'BumBumBole.gif', 'clcoding.pdf', 'file1.pdf']
Python Coding August 15, 2022 Python No comments
import pyshorteners
long_url = input("Enter the URL to shorten: ")
##TinyURL shortener service
type_tiny = pyshorteners.Shortener()
short_url = type_tiny.tinyurl.short(long_url)
print("The Shortened URL is: " + short_url)
#clcoding.com
Enter the URL to shorten: https://www.clcoding.com/p/python.html The Shortened URL is: https://tinyurl.com/2zb6hedv
Python Coding August 15, 2022 Python No comments
import PyPDF2
import pyttsx3
engine = pyttsx3.init()
# Read the pdf by specifying the path in your computer
pdfReader = PyPDF2.PdfFileReader(open('clcoding.pdf', 'rb'))
# Get the handle to speaker
speaker = pyttsx3.init()
# split the pages and read one by one
for page_num in range(pdfReader.numPages):
text = pdfReader.getPage(page_num).extractText()
speaker.say(text) #clcoding.com
speaker.runAndWait()
# stop the speaker after completion
speaker.stop()
# save the audiobook at specified path
engine.save_to_file(text, 'E:\audio.mp3')
engine.runAndWait()
Python Coding August 15, 2022 Python No comments
from PIL import Image, ImageDraw, ImageFont
img = Image.open(r'binod.jpg')
draw = ImageDraw.Draw(img)
text = "clcoding.com"
font = ImageFont.truetype('arial.ttf', 50)
textwidth, textheight = draw.textsize(text, font)
width, height = img.size
x=width/2-textwidth/2
y=height-textheight-50
draw.text((x, y), text, font=font)
img.save(r'binod.png')
Image.open('binod.png')
Python Coding August 15, 2022 Python No comments
import emoji
print(emoji.emojize(":India:"))
print(emoji.emojize(":books:"))
print(emoji.emojize(":red_heart:"))
print(emoji.emojize(":hibiscus:"))
print(emoji.emojize(":rose:"))
print(emoji.emojize(":baby:"))
#clcoding.com
๐ฎ๐ณ ๐ ❤️ ๐บ ๐น ๐ถ
Python Coding August 15, 2022 Python No comments
from captcha. Image import ImageCaptcha
# Specify the image size
image = ImageCaptcha(width = 300, height = 100)
# Specify the Text for captcha
captcha_text = input("Enter Captcha text : ")
# generate the image of the given text
data = image.generate(captcha_text)
#clcoding.com
# write the image on the given file and save it
image.write(captcha_text, 'E:\CAPTCHA1.png')
from PIL import Image
Image.open('E:\CAPTCHA1.png')
Enter Captcha text : python
Python Coding August 15, 2022 Python No comments
Number = int(input("Enter the Number to Check Disarium Number = "))
length = len(str(Number))
Temp = Number
Sum = 0
rem = 0 #clcoding.com
while Temp > 0:
rem = Temp % 10
Sum = Sum + int(rem**length)
Temp = Temp // 10
length = length - 1
print("The Sum of the Digits = %d" %Sum)
if Sum == Number:
print("\n%d is a Disarium Number." %Number)
else:
print("%d is Not a Disarium Number." %Number)
Enter the Number to Check Disarium Number = 175 The Sum of the Digits = 175 175 is a Disarium Number.
Python Coding August 15, 2022 Python No comments
from geopy.geocoders import Nominatim
# Using Nominatim Api
geolocator = Nominatim(user_agent="geoapiExercises")
# Zipocde input
a = input("Enter the zipcode : ")
zipcode = a
# Using geocode()
location = geolocator.geocode(zipcode)
# Displaying address details
print("Zipcode:",zipcode)
print("Details of the Zipcode:")
print(location)
#clcoding.com
Enter the zipcode : 411045 Zipcode: 411045 Details of the Zipcode: Pune City, Maharashtra, 411045, India
Python Coding August 15, 2022 Python No comments
import imageio
filenames = ["1.png","3.png","4.png"]
#you can add any type of image
images = []
for filename in filenames:
images.append(imageio.imread(filename))
imageio.mimsave('ritesh1.gif', images,'GIF',duration=1)
#you can add duration as per your need
#clcoding.com
Python Coding August 14, 2022 Python No comments
# Swap function
def swapList(newList):
size = len(newList)
# Swapping
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
# Driver code
newList = []
newList = [int(item) for item in input("Enter the list items : ").split()]
print(swapList(newList))
#clcoding.com
Enter the list items : 4 5 2 3 8 6 [6, 5, 2, 3, 8, 4]
Python Coding August 14, 2022 Python No comments
# Function to find permutations of a given string
from itertools import permutations
def allPermutations(str):
permList = permutations(str)
# print all permutations
for perm in list(permList):
print (''.join(perm))
# Driver program
if __name__ == "__main__":
str = input("Enter your string : ")
allPermutations(str)
#clcoding.com
Enter your string : CAT CAT CTA ACT ATC TCA TAC
Python Coding August 14, 2022 Python No comments
# Python program to find compound interest
def compound_interest(principle, rate, time):
# Calculates compound interest
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print("Compound interest is", CI)
P=float(input("Enter Principle Value : "))
R=float(input("Enter Rate Value : "))
T=float(input("Enter Time Value : "))
compound_interest(P,R,T)
#clcoding.com
Enter Principle Value : 1000 Enter Rate Value : 11 Enter Time Value : 3 Compound interest is 367.6310000000003
Python Coding August 14, 2022 Python No comments
# Python program to add two numbers
number1 = input("First number: ")
number2 = input("Second number: ")
# Adding two numbers
# User might also enter float numbers
sum = float(number1) + float(number2)
# Display the sum
# will print value in float
print("The sum of {0} and {1} is {2}" .format(number1, number2, sum))
#clcoding.com
First number: 21
Second number: 31
The sum of 21 and 31 is 52.0
Python Coding August 14, 2022 Python No comments
print("Enter the Number of Rows: ", end="")
row = int(input())
num = 1
for i in range(row):
for j in range(i+1):
print(num, end=" ")
num = num+1
print()
#clcoding.com
Enter the Number of Rows: 6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Python Coding August 14, 2022 Python No comments
# To take input from the user
num = int(input("Enter a number : "))
factorial = 1
# check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
#clcoding.com
Enter a number : 6 The factorial of 6 is 720
Python Coding August 14, 2022 Python No comments
import time
def countdown(time_sec):
while time_sec:
mins, secs = divmod(time_sec, 60)
timeformat = '{:02d}:{:02d}'.format(mins, secs)
print(timeformat, end='\r')
time.sleep(1)
time_sec -= 1
print("stop")
num=int(input("Set Your Timer in Sec : "))
countdown(num)
#clcoding.com
Set Your Timer in Sec : 10 stop1
Python Coding August 14, 2022 Python No comments
# define punctuation
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
# To take input from the user
my_str = input("Enter Your String : ")
# remove punctuation from the string
no_punct = ""
for char in my_str:
if char not in punctuations:
no_punct = no_punct + char
#clcoding.com
# display the unpunctuated string
print(no_punct)
Enter Your String : " I love Python"! I love Python
Python Coding August 14, 2022 Python No comments
# Python Program to find the factors of a number
# This function computes the factor of the argument passed
def print_factors(x):
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
num=int(input("Enter a Number to find the Fators : "))
print_factors(num)
#clcoding.com
Enter a Number to find the Fators : 26 The factors of 26 are: 1 2 13 26
Python Coding August 14, 2022 Python No comments
# Program to display the Fibonacci sequence up to n-th term
nterms = int(input("How many terms? "))
# first two terms
n1, n2 = 0, 1
count = 0
# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1 #clcoding.com
How many terms? 7 Fibonacci sequence: 0 1 1 2 3 5 8
Python Coding August 14, 2022 Python No comments
# take input from the user
num = int(input("Enter a number: "))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
#clcoding.com
Enter a number: 477 477 is not an Armstrong number
Python Coding August 14, 2022 Python No comments
#pip install PyPDF2
from PyPDF2 import PdfFileWriter, PdfFileReader
import getpass
pdfwriter=PdfFileWriter()
pdf=PdfFileReader('E:\\clcoding.pdf')
for page_num in range(pdf.numPages):
pdfwriter.addPage(pdf.getPage(page_num))
password=getpass.getpass(prompt='Enter Password: ')
pdfwriter.encrypt(password)
with open('E:\\clcoding.pdf','wb') as f:
pdfwriter.write(f)
print("Now File is password protected")
#clcoding.com
Enter Password: ········ Now File is password protected
Python Coding August 14, 2022 Python No comments
import matplotlib.pyplot as pyplot
# Create data
riding = ((17, 18, 21, 22, 19, 21, 25, 22, 25, 24),(3, 6, 3.5, 4, 5, 6.3, 4.5, 5, 4.5, 4))
swimming = ((17, 18, 20, 19, 22, 21, 23, 19, 21, 24),(8, 9, 7, 10, 7.5, 9, 8, 7, 8.5, 9))
sailing = ((31, 28, 29, 36, 27, 32, 34, 35, 33, 39),(4, 6.3, 6, 3, 5, 7.5, 2, 5, 7, 4))
# Plot the data
pyplot.scatter(x=riding[0], y=riding[1], c='red', marker='s',label='riding')
pyplot.scatter(x=swimming[0], y=swimming[1], c='green',marker='o', label='swimming')
pyplot.scatter(x=sailing[0], y=sailing[1], c='blue',marker='*', label='sailing')
# Configure graph
pyplot.xlabel('Age')
pyplot.ylabel('Hours')
pyplot.title('Activities Scatter Graph')
pyplot.legend()
pyplot.show()
#clcoding.com
Python Coding August 14, 2022 Python No comments
import random
import math
lower = int(input("Enter Lower bound:- "))
upper = int(input("Enter Upper bound:- "))
# generating random number between the lower and upper
x = random.randint(lower, upper)
print("\n\tYou've only ",round(math.log(upper - lower + 1, 2)),
" chances to guess the integer!\n")
# Initializing the number of guesses.
count = 0 #clcoding.com
# for calculation of minimum number of guesses depends upon range
while count < math.log(upper - lower + 1, 2):
count += 1
# taking guessing number as input
guess = int(input("Guess a number:- "))
# Condition testing
if x == guess:
print("Congratulations you did it in ",count, " try")
break
elif x > guess:
print("You guessed too small!")
elif x < guess:
print("You Guessed too high!")
# shows this output.
if count >= math.log(upper - lower + 1, 2):
print("\nThe number is %d" % x)
print("\tBetter Luck Next time!")
Enter Lower bound:- 1 Enter Upper bound:- 10 You've only 3 chances to guess the integer! Guess a number:- 6 Congratulations you did it in 1 try
Python Coding August 14, 2022 Python No comments
Python Coding August 13, 2022 Python No comments
import hashlib
BLOCKSIZE = 65536
# Block read size if file is big enough
fileToOpen = 'E:\\new_python\\new_doc2.txt'
hasher = hashlib.md5()
with open(fileToOpen, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(BLOCKSIZE)
print(hasher.hexdigest())
#clcoding.com
d41d8cd98f00b204e9800998ecf8427e
Python Coding August 13, 2022 Python No comments
import os
# Path IN which we have to count files and directories
PATH = 'E:\elements' # Give your path here
fileCount = 0
dirCount = 0
for root, dirs, files in os.walk(PATH):
print('Looking in:',root)
for directories in dirs:
dirCount += 1
for Files in files:
fileCount += 1
#clcoding.com
print('Number of files',fileCount)
print('Number of Directories',dirCount)
print('Total:',(dirCount + fileCount))
Looking in: E:\elements Looking in: E:\elements\New folder Number of files 8 Number of Directories 1 Total: 9
Python Coding August 13, 2022 Python No comments
def SieveOfEratosthenes(n):
primes = [True] * (n + 1)
p = 2 # because p is the smallest prime
while(p * p <= n):
# if p is not marked as False, this it is a prime
if(primes[p]) == True:
# mark all the multiples of number as False
for i in range(p * 2, n + 1, p):
primes[i] = False
p += 1
# printing all primes
for i in range(2, n):
if primes[i]:
print(i)
if __name__ == '__main__':
n=int(input("Enter a no to check all smaller prime numbers :"))
SieveOfEratosthenes(n)
#clcoding.com
Enter a no to check all smaller prime numbers :20 2 3 5 7 11 13 17 19
Free Books Python Programming for Beginnershttps://t.co/uzyTwE2B9O
— Python Coding (@clcoding) September 11, 2023
Top 10 Python Data Science book
— Python Coding (@clcoding) July 9, 2023
๐งต:
Top 4 free Mathematics course for Data Science ! pic.twitter.com/s5qYPLm2lY
— Python Coding (@clcoding) April 26, 2024
Web Development using Python
— Python Coding (@clcoding) December 2, 2023
๐งต: