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

Tuesday, 12 November 2024

Convert RGB to Hex using Python

 

from webcolors import name_to_hex


def color_name_to_code(color_name):

    try:

        color_code = name_to_hex(color_name)

        return color_code

    except ValueError:

        return None

        

colorname = input("Enter color name : ")

result_code = color_name_to_code(colorname)

print(result_code)  


Monday, 11 November 2024

PDF file protection using password in Python

 

from PyPDF2 import PdfReader, PdfWriter
import getpass

def protect_pdf(input_pdf, output_pdf):
    reader = PdfReader('clcoding.pdf')
    writer = PdfWriter()

    for page in reader.pages:
        writer.add_page(page)

    password = getpass.getpass("Enter a password : ")
    writer.encrypt(password)
    with open(output_pdf, "wb") as output_file:
        writer.write(output_file)
    print(f"The PDF has password.")
    
protect_pdf("clcoding.pdf", "protected_file.pdf")

Saturday, 9 November 2024

Rainbow Circle using Python

 

import turtle

t = turtle.Turtle()

t.speed(10)

colors = ['red', 'orange', 'yellow',

          'green', 'blue', 'indigo',

          'violet']

turtle.bgcolor('black')

for i in range(36):

    t.color(colors[i % 7])

    t.circle(100)

    t.right(10)

turtle.done()


Saturday, 2 November 2024

Automating Excel with Python

 

Automating Excel with Python 


In Automating Excel with Python: Processing Spreadsheets with OpenPyXL you will learn how to use Python to create, edit or read Microsoft Excel documents using OpenPyXL.


Python is a versatile programming language. You can use Python to read, write and edit Microsoft Excel documents. There are several different Python packages you can use, but this book will focus on OpenPyXL.

The OpenPyXL package allows you to work with Excel files on Windows, Mac and Linux, even if Excel isn't installed.

In this book, you will learn about the following:

  • Opening and Saving Workbooks

  • Reading Cells and Sheets

  • Creating a Spreadsheet (adding / deleting rows and sheets, merging cells, folding, freeze panes)

  • Cell Styling (font, alignment, side, border, images)

  • Conditional Formatting

  • Charts

  • Comments

  • and more!

Python is a great language that you can use to enhance your daily work, whether you are an experienced developer or a beginner!

Automating Excel with Python

Retrieve System Information using Python

 

import wmi


c = wmi.WMI()


for os in c.Win32_OperatingSystem():

    

    print(f"OS Name: {os.Name}")

    print(f"Version: {os.Version}")

    print(f"Manufacturer: {os.Manufacturer}")

    print(f"Architecture: {os.OSArchitecture}")

Friday, 1 November 2024

Python Code for Periodic Table

 

import periodictable


Atomic_No = int(input("Enter Atomic No :"))


element = periodictable.elements[Atomic_No]

print('Name:', element.name)

print('Symbol:', element.symbol)

print('Atomic mass:', element.mass)

print('Density:', element.density)


#source code --> clcoding.com

Name: zinc

Symbol: Zn

Atomic mass: 65.409

Density: 7.133

Tuesday, 29 October 2024

Monday, 28 October 2024

Sunday, 27 October 2024

Finally release your stress while Coding

 

About this item

[Good material] It is made of high-quality pearl foam material, it is not easy to age, durable and has a long service life.

[Big Enter Button]The Big Enter key is a button that is almost 6 times bigger than the real key. Dubbed as the "BIG ENTER", this is easy to use.

[Compatibility] All you need to do is to plug in the USB cable into your PC,laptop and it'll recognize as an "ENTER" key, it is compatibility with all operation systems such as windows,mac,linux etc .

[A pillow for your nap]The button itself is made out of soft sponge material so when you get tired, you can even use it as a pillow and take a nap on it.

[Release pressure]And when you're feeling stressed out, you can smash on it as hard as you can without fearing of breaking your keyboard. 

USA Buy: Finally release your stress while Coding

India Buy: Finally release your stress while Coding

Europe: Finally release your stress while Coding

Thursday, 24 October 2024

Monday, 21 October 2024

Find director of a movie using Python

 

from imdb import IMDb


ia = IMDb()

movie_name = input("Enter the movie name: ")

movies = ia.search_movie(movie_name)


if movies:

    movie = movies[0]

    ia.update(movie)

    directors = movie.get('directors')

    if directors:

        print("Director(s):")

        for director in directors:

            print(director['name'])

    else:

        print("No director information found.")

else:

    print("Movie not found.")

Sunday, 20 October 2024

Find your country on a Map using Python

 


import plotly.express as px


country = input("Enter the country name: ")

data = {

    'Country': [country],

    'Values': [100]  }

fig = px.choropleth(

    data,

    locations='Country',

    locationmode='country names',

    color='Values',

    color_continuous_scale='Inferno',

    title=f'Country Map Highlighting {country}')

fig.show()


#source code --> clcoding.com

Sunday, 13 October 2024

Friday, 11 October 2024

Python Coding challenge - Day 245 | What is the output of the following Python Code?

 

Let's break down the code step by step to explain what happens in the modify_list function and why the final result of print(my_list) is [1, 2, 3, 4].


def modify_list(lst, val):

    lst.append(val)

    lst = [100, 200, 300]


my_list = [1, 2, 3]

modify_list(my_list, 4)

print(my_list)

Step-by-step Explanation:

Function Definition: The function modify_list(lst, val) accepts two arguments:


lst: a list passed by reference (so modifications within the function affect the original list unless reassigned).

val: a value that will be appended to the list lst.

Initial State of my_list: Before calling the function, the list my_list is initialized with the values [1, 2, 3].


Calling the Function:


modify_list(my_list, 4)

We pass the list my_list and the value 4 as arguments to the function.

Inside the function, lst refers to the same list as my_list because lists are mutable and passed by reference.

First Line Inside the Function:


lst.append(val)

lst.append(4) adds the value 4 to the list.

Since lst refers to the same list as my_list, this operation modifies my_list as well.

At this point, my_list becomes [1, 2, 3, 4].

Reassignment of lst:


lst = [100, 200, 300]

This line creates a new list [100, 200, 300] and assigns it to the local variable lst.

However, this reassignment only affects the local variable lst inside the function. It does not modify the original list my_list.

After this line, lst refers to the new list [100, 200, 300], but my_list remains unchanged.

End of the Function: When the function finishes execution, lst (which is now [100, 200, 300]) is discarded because it was only a local variable.


my_list retains its modified state from earlier when the value 4 was appended.

Final Output:

print(my_list)

When we print my_list, it shows [1, 2, 3, 4] because the list was modified by lst.append(val) but not affected by the reassignment of lst.

Key Takeaways:

List Mutation: The append() method modifies the list in place, and since lists are mutable and passed by reference, my_list is modified by lst.append(val).

Local Reassignment: The line lst = [100, 200, 300] only reassigns lst within the function's scope. It does not affect my_list outside the function because the reassignment creates a new list that is local to the function.

Thus, the final output is [1, 2, 3, 4].







Thursday, 10 October 2024

Density plot using Python


 import seaborn as sns

import matplotlib.pyplot as plt

import numpy as np


data = np.random.normal(size=1000)

sns.kdeplot(data, fill=True, color="blue")


plt.title("Density Plot")

plt.xlabel("Value")

plt.ylabel("Density")

plt.show()


#source code --> clcoding.com

Wednesday, 9 October 2024

Map chart using Python

 

import plotly.express as px


data = {

    'Country': ['United States', 'Canada',

                'Brazil', 'Russia', 'India'],

    'Values': [100, 50, 80, 90, 70]

}

fig = px.choropleth(

    data,

    locations='Country',      

    locationmode='country names',

    color='Values',           

    color_continuous_scale='Blues',

    title='Choropleth Map of Values by Country')

fig.show()

Gauge charts using Python

 

import plotly.graph_objects as go


fig = go.Figure(go.Indicator(

    mode="gauge+number",

    value=65,

    title={'text': "Speed"},

    gauge={'axis': {'range': [0, 100]},

           'bar': {'color': "darkblue"},

           'steps': [{'range': [0, 50], 'color': "lightgray"},

                     {'range': [50, 100], 'color': "gray"}],

           'threshold': {'line': {'color': "red", 'width': 4},

                         'thickness': 0.75, 'value': 80}}))

fig.show()


#source code --> clcoding.com

Tuesday, 8 October 2024

Waterfall Chart using Python

 

import plotly.graph_objects as go


fig = go.Figure(go.Waterfall(

    name = "20", orientation = "v",

    measure = ["relative", "relative", "total", "relative",

               "relative", "total"],

    x = ["Sales", "Consulting", "Net revenue", "Purchases",

         "Other expenses", "Profit before tax"],

    textposition = "outside",

    text = ["+60", "+80", "", "-40", "-20", "Total"],

    y = [60, 80, 0, -40, -20, 0],

    connector = {"line":{"color":"rgb(63, 63, 63)"}},

))


fig.update_layout(

        title = "Profit and loss statement 2024",

        showlegend = True

)

fig.show()


#source code --> clcoding.com

Pareto Chart using Python

 

import pandas as pd

import matplotlib.pyplot as plt


data = {'Category': ['A', 'B', 'C', 'D', 'E'],

        'Frequency': [50, 30, 15, 5, 2]}


df = pd.DataFrame(data)

df = df.sort_values('Frequency', ascending=False)

df['Cumulative %'] = df['Frequency'].cumsum() / df['Frequency'].sum() * 100


fig, ax1 = plt.subplots()

ax1.bar(df['Category'], df['Frequency'], color='C4')

ax1.set_ylabel('Frequency')


ax2 = ax1.twinx()

ax2.plot(df['Category'], df['Cumulative %'], 'C1D')

ax2.set_ylabel('Cumulative %')


plt.title('Pareto Chart')

plt.show()


#source code --> clcoding.com

Python programming workbook for IoT Development with Raspberry pi and MQTT: Hands-on Projects and exercises for building smart devices and IoT ... programming and code mastery books)

 

Ready to turn your Raspberry Pi into a smart device powerhouse?

This Python workbook is your ticket to building incredible IoT applications using MQTT, the communication protocol behind the Internet of Things. It's packed with hands-on projects that take you from beginner to builder, one step at a time.

What's inside?

  • Learn by doing: Forget boring theory – we dive right into building smart home systems, environmental monitors, and more.
  • Master MQTT: Understand this essential protocol, the backbone of IoT communication.
  • Python skills made easy: Develop your coding confidence and create powerful IoT devices.
  • Problem-solving: Get past common hurdles like complex coding, connectivity issues, data management, and security concerns.

Who's it for?

Whether you're a hobbyist tinkering in your garage, a student eager to learn, or an aspiring IoT developer, this workbook is your guide.

It's time to unleash the power of the Internet of Things.

Hard Copy : Python programming workbook for IoT Development with Raspberry pi and MQTT: Hands-on Projects and exercises for building smart devices and IoT ... programming and code mastery books)

Popular Posts

Categories

AI (32) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (146) C (77) C# (12) C++ (82) Course (67) Coursera (198) Cybersecurity (24) data management (11) Data Science (106) Data Strucures (8) Deep Learning (13) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (21) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (888) Python Coding Challenge (285) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

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