Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Saturday 9 April 2022

Day 7 : Treemap using Python



#!/usr/bin/env python
# coding: utf-8

# # Treemap using Python

# In[2]:


import plotly.graph_objects as go

fig = go.Figure(go.Treemap(
    labels = ["A","B", "C", "D", "E", "F", "G", "H", "I"],
    parents = ["", "A", "A", "C", "C", "A", "A", "G", "A"]
))

fig.show()

#clcoding.com


# In[ ]:




Sunday 3 April 2022

Day 6 : Text to Handwriting using Python



#!/usr/bin/env python
# coding: utf-8

# # Text to Handwriting using Python

# In[ ]:


import pywhatkit as kit
import cv2
Handwritten=input("Enter your text to convert in Handwriting : ")
kit.text_to_handwriting(Handwritten, save_to="pythoncoding.png")
img = cv2.imread("pythoncoding.png")
cv2.imshow("Python Coding", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

#clcoding.com


# In[ ]:




Day 5 : Roman Numbers to Decimals in Python


 

#!/usr/bin/env python

# coding: utf-8


# # Roman Numbers to Decimals in Python


# In[6]:



tallies = {'I': 1,'V': 5,'X': 10,'L': 50,

           'C': 100,'D': 500,'M': 1000}

def RomanNumeralToDecimal(romanNumeral):

    sum = 0

    for i in range(len(romanNumeral) - 1):

        left = romanNumeral[i]

        right = romanNumeral[i + 1]

        if tallies[left] < tallies[right]:

            sum -= tallies[left]

        else:

            sum += tallies[left]

    sum += tallies[romanNumeral[-1]]

    return sum 

roman=input("Enter Roman Numbers :")

RomanNumeralToDecimal(roman)


#clcoding.com



# In[ ]:





Day 4 : LCM using Python



#!/usr/bin/env python
# coding: utf-8

# # LCM using Python

# In[13]:


def least_common_multiple(a,b):
  
    if a > b:
        greater = a
    elif b > a:
        greater = b
    while(True):
        if ((greater % a == 0) and (greater % b == 0)):
            lcm = greater
            break
        greater = greater + 1
    return lcm
a=int(input("Enter 1st number: "))
b=int(input("Enter 2nd number: "))
print(least_common_multiple(a,b))

#clcoding.com


# In[ ]:




Day 3 : Palindrome Words using Python



#!/usr/bin/env python
# coding: utf-8

# # Palindrome Words using Python

# In[6]:


def palindrome(sentence):
    for i in (",.'?/><}{{}}'"):
        sentence = sentence.replace(i, "")
    palindrome = []
    words = sentence.split(' ')
    for word in words:
        word = word.lower()
        if word == word[::-1]:
            palindrome.append(word)
    return palindrome
sentence = input("Enter a sentence : ")
print(palindrome(sentence))

#clcoding.com


# In[ ]:




Day 2 : Count Character Occurrences using Python


 

#!/usr/bin/env python

# coding: utf-8


# # Count Character Occurrences using Python


# In[5]:



def count_characters(s):

    count = {}

    for i in s:

        if i in count:

            count[i] += 1

        else:

            count[i] = 1

    print(count)

word=input("Enter your string:")

count_characters(word)


#clcoding.com


Day 1: Line continuation characters in Python


#!/usr/bin/env python
# coding: utf-8

# # Day 1 :  Line continuation characters in Python

# In[28]:


print("I know Python and its very easy for everyone")


# In[29]:


print("I know Python and
its very easy for everyone")

#clcoding.com


# In[30]:


#In Python, a backslash ( \ ) is a continuation character.

print("I know Python and its very easy for everyone")

#clcoding.com


# In[ ]:




Tuesday 29 March 2022

How to generate password using python?

random: 
Python has a built-in module that you can use to make random numbers.
The random module has a set of methods:

  • random(): Returns a random float number between 0 and 1
  • sample(): Returns a given sample of a sequence
  • shuffle(): Takes a sequence and returns the sequence in a random order
  • choice(): Returns a random element from the given sequence
  • choices(): Returns a list with a random selection from the given sequence
  • randint(): Returns a random number between the given range
  • uniform(): Returns a random float number between two given parameters

array:
An array is a collection of items stored at contiguous memory locations. 
This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers.

import random
import array

#  password length
MAX_LEN = 12


DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
LOCASE_CHARACTERS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z']

UPCASE_CHARACTERS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z']

SYMBOLS = ['@', '#', '$', '%', '=', ':', '?', '.', '/', '|', '~', '>',
'*', '(', ')', '<']

# combines all the character arrays above to form one array
COMBINED_LIST = DIGITS + UPCASE_CHARACTERS + LOCASE_CHARACTERS + SYMBOLS

# randomly select at least one character from each character set above
rand_digit = random.choice(DIGITS)
rand_upper = random.choice(UPCASE_CHARACTERS)
rand_lower = random.choice(LOCASE_CHARACTERS)
rand_symbol = random.choice(SYMBOLS)

# combine the character randomly selected above

temp_pass = rand_digit + rand_upper + rand_lower + rand_symbol



# the password length by selecting randomly from the combined

for x in range(MAX_LEN - 4):
temp_pass = temp_pass + random.choice(COMBINED_LIST)

# changing the position of the elements of the sequence.

temp_pass_list = array.array('u', temp_pass)
random.shuffle(temp_pass_list)

# traverse the temporary password array and append the charsto form the password
password = ""
for x in temp_pass_list:
password = password + x
# print out password
print(password)




Thank you ๐Ÿ˜Š for reading. Please read other blogs. And also share with your friends and 
family.
Please also go to following blog:   https://pythoholic.blogspot.com/

Friday 25 March 2022

Sequence Matcher in Python

 


#!/usr/bin/env python

# coding: utf-8


# # Sequence Matcher in Python


# In[3]:



from difflib import SequenceMatcher

text1 = input("Enter 1st sentence : ") 

text2 = input("Enter 2nd sentence : ")

sequenceScore = SequenceMatcher(None, text1, text2).ratio()

print(f"Both are {sequenceScore * 100} % similar")


#clcoding.com



# In[ ]:





Age Calculator using Python

 

#!/usr/bin/env python
# coding: utf-8

# # Age Calculator using Python

# In[20]:


def ageCalculator(y, m, d):
    import datetime
    today = datetime.datetime.now().date()
    dob = datetime.date(y, m, d)
    age = int((today-dob).days / 365.25)
    print(age)

#y=year m=month d=day    
ageCalculator(2001 , 8, 1)

#clcoding.com


# In[ ]:




Saturday 19 March 2022

Image to Pencil Sketch in Python


#!/usr/bin/env python
# coding: utf-8

# # Image to Pencil Sketch in Python 

# In[ ]:


#...........Convert image to pencil sketch......!
import cv2

#specify the path to image (Loading image image)
image1 = cv2.imread('E:\demo.png')
window_name = 'Original image'

# Displaying the original image 
cv2.imshow(window_name,image1)


# convert the image from one color space to another
grey_img = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
invert = cv2.bitwise_not(grey_img)

#image smoothing
blur = cv2.GaussianBlur(invert, (21, 21), 0)
invertedblur = cv2.bitwise_not(blur)
sketch = cv2.divide(grey_img, invertedblur, scale=256.0)

#save the converted image to specified path
cv2.imwrite("E:\sketch.png", sketch)
 
# Reading an image in default mode
image = cv2.imread("E:\sketch.png")
  
# Window name in which image is displayed
window_name = 'Sketch image'
  
# Displaying the sketch image 
cv2.imshow(window_name, image)
#waits for user to press any key 
#(this is necessary to avoid Python kernel form crashing)
cv2.waitKey(0) 
  
#closing all open windows 
cv2.destroyAllWindows() 


# In[ ]:




Sunday 13 March 2022

Voice Recorder in Python




#!/usr/bin/env python
# coding: utf-8

# In[13]:


pip install sounddevice


# In[14]:


pip install scipy


# # Voice Recorder in Python

# In[15]:


#import required modules
import sounddevice
from scipy.io.wavfile import write
#sample_rate
fs=44100

#Ask to enter the recording time
second=int(input("Enter the Recording Time in second: "))
print("Recording....\n")
record_voice=sounddevice.rec(int(second * fs),samplerate=fs,channels=2)
sounddevice.wait()
write("MyRecording.wav",fs,record_voice)
print("Recording is done Please check you folder to listen recording")

#clcoding.com


# In[ ]:




Download YouTube videos in Python




#!/usr/bin/env python
# coding: utf-8

# # Download YouTube videos in Python

# In[1]:


pip install pytube


# In[1]:


#import pytube library to download the video
import pytube

#Ask for the url of video
url = input("Enter video url: ")
#we can take path as well, just uncomment the following line
#path = input("Enter path of storage")
 
#specify the starage path of video
path="E:"

#magic line to download the video
pytube.YouTube(url).streams.get_highest_resolution().download(path)

#clcoding.com


# In[ ]:





# In[ ]:




Captcha in Python




#!/usr/bin/env python
# coding: utf-8

# In[1]:


pip install captcha


# # Generate Image captcha in python:

# In[12]:


from captcha.image import ImageCaptcha
   
# Specify the image size
image = ImageCaptcha(width = 300, height = 100)
# Specify the Text for captcha
captcha_text = 'python clcoding'
   
# generate the image of the given text
data = image.generate(captcha_text)  
   
# write the image on the given file and save it
image.write(captcha_text, 'E:\CAPTCHA1.png')


# # Generate audio captcha in python:

# In[13]:


from captcha.audio import AudioCaptcha
   
# Create an audio instance
audio = AudioCaptcha()  
   
# Text for captcha
captcha_text = "1011011"
   
# generate the audio of the given text
audio_captcha = audio.generate(captcha_text)
 
# specify the file name and path
audio.write(captcha_text, 'E:\Audio_Captcha.wav')


# In[ ]:




Secrets Python module







#!/usr/bin/env python
# coding: utf-8

# # secrets.randbelow(n): This function returns a random integer in the range [0, n)


# In[1]:



import secrets
  
passwd = secrets.randbelow(100)
print(passwd)


# # secrets.randbits(k): This function returns an int with k random bits

# In[2]:


import secrets

passwd=secrets.randbits(4)
print(passwd)


# # Generate a ten-character alphanumeric password.

# In[3]:


#clcoding.com
import secrets
import string
  
alphabet = string.ascii_letters + string.digits
password = ''.join(secrets.choice(alphabet) for i in range(10))
  
print(password)


# # Generate a ten-character alphanumeric password with at least one   lowercase character, at least one uppercase character,                                      and at least three digits.

# In[4]:


#clcoding.com
import secrets
import string

alphabet = string.ascii_letters + string.digits
while True:
password = ''.join(secrets.choice(alphabet) for i in range(10))
if (any(c.islower() for c in password) and any(c.isupper()
for c in password) and sum(c.isdigit() for c in password) >= 3):
print(password)
break


# In[ ]:




Saturday 5 March 2022

Mouse and keyboard automation using Python


#!/usr/bin/env python
# coding: utf-8

# # Mouse and keyboard automation using Python

# In[31]:


import pyautogui
print(pyautogui.size())


# In[32]:


#moveTo(): use this function to move the mouse in pyautogui module. 
pyautogui.moveTo(100, 100, duration = 5)


# In[33]:


#moveRel() function: moves the mouse pointer relative to its previous position. 
pyautogui.moveRel(0, 50, duration = 5)


# In[34]:


#position(): function to get current position of the mouse pointer. 
print(pyautogui.position())


# In[35]:


#click(): Function used for clicking and dragging the mouse. 
pyautogui.click(100, 1000)


# In[36]:


#clcoding.com

Friday 4 March 2022

Python Secrets Module

#!/usr/bin/env python
# coding: utf-8

# # secrets.randbelow(n): This function returns a random integer in the range [0, n)

# In[16]:



import secrets
  
passwd = secrets.randbelow(100)
print(passwd)


# # secrets.randbits(k): This function returns an int with k random bits

# In[17]:


import secrets

passwd=secrets.randbits(4)
print(passwd)


# # Generate a ten-character alphanumeric password.

# In[19]:


#clcoding.com
import secrets
import string
  
alphabet = string.ascii_letters + string.digits
password = ''.join(secrets.choice(alphabet) for i in range(10))
  
print(password)


# # Generate a ten-character alphanumeric password with at least one   lowercase character, at least one uppercase character,                                      and at least three digits.

# In[21]:


#clcoding.com
import secrets
import string

alphabet = string.ascii_letters + string.digits
while True:
password = ''.join(secrets.choice(alphabet) for i in range(10))
if (any(c.islower() for c in password) and any(c.isupper()
for c in password) and sum(c.isdigit() for c in password) >= 3):
print(password)
break


# In[ ]:




Monday 28 February 2022

Digital Watch in Python using Turtle

#Code:

#!/usr/bin/env python
# coding: utf-8

# In[ ]:


import time

import datetime as dt

import turtle

# create a turtle to display time

t = turtle.Turtle()

# create a turtle to create rectangle box

t1 = turtle.Turtle()

# create screen

s = turtle.Screen()

# set background color of the screen

s.bgcolor("cyan")

# obtain current hour, minute and second 

# from the system

sec = dt.datetime.now().second

min = dt.datetime.now().minute

hr = dt.datetime.now().hour

t1.pensize(10)

t1.color('red')

t1.penup()

# set the position of turtle

t1.goto(-20, -0)

t1.pendown()

# create rectangular box

for i in range(2):

 t1.forward(200)

 t1.left(90)

 t1.forward(70)

 t1.left(90)

#clcoding.com
# hide the turtle

t1.hideturtle()

while True:

 t.hideturtle()

 t.clear()

 # display the time

 t.write(str(hr).zfill(2)

 +":"+str(min).zfill(2)+":"

 +str(sec).zfill(2),

 font =("Arial Narrow", 35, "bold"))

 time.sleep(1)

 sec+= 1

 if sec == 60:

    sec = 0

    min+= 1

 if min == 60:

    min = 0

    hr+= 1

 if hr == 13:

    hr = 1

Saturday 26 February 2022

Creating an Audiobook in Python






#!/usr/bin/env python
# coding: utf-8

# In[31]:


pip install PyPDF2


# In[32]:


pip install pyttsx3


# In[33]:


#pip install PyPDF2
import PyPDF2


# In[34]:


#pip install pyttsx3
import pyttsx3


# In[35]:


pdfReader=PyPDF2.PdfFileReader(open('C:\\Users\\Irawen\\Documents\\embedded\\Python\\clcoding.pdf','rb'))


# In[36]:


speaker = pyttsx3.init()


# In[37]:


for page_num in range(pdfReader.numPages):
    text =  pdfReader.getPage(page_num).extractText()
    speaker.say(text)
    speaker.runAndWait()


# In[38]:


speaker.stop()


# In[ ]:




Python module whatismyip




#!/usr/bin/env python
# coding: utf-8

# # Python module to find out your IP address:

# In[2]:


pip install whatismyip


# In[13]:


import whatismyip


# In[14]:


whatismyip.amionline()


# In[15]:


whatismyip.whatismyip()


# In[16]:


whatismyip.whatismyipv4()


# In[17]:


whatismyip.whatismyipv6()


# In[ ]:




Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (114) C (77) C# (12) C++ (82) Course (60) Coursera (176) coursewra (1) Cybersecurity (22) data management (11) Data Science (87) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (740) Python Coding Challenge (187) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses