Tuesday 3 May 2022

Day 28 : Bar Graph using Matplotlib in Python




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

# # Bar Graph using Matplotlib in Python

# In[2]:


import matplotlib.pyplot as pyplot
# Set up the data
labels = ('Python', 'Scala', 'C#', 'Java', 'PHP')
index = (1, 2, 3, 4, 5) # provides locations on x axis
sizes = [45, 10, 15, 30, 22]
# Set up the bar chart
pyplot.bar(index, sizes, tick_label=labels)
# Configure the layout
pyplot.ylabel('Usage')
pyplot.xlabel('Programming Languages')
# Display the chart
pyplot.show() #clcoding.com


# In[ ]:




Day 27 : Pie Charts using Matplotlib in Python

 



#!/usr/bin/env python

# coding: utf-8


# # Pie Charts using Matplotlib in Python


# In[2]:



#Pie Charts using Matplotlib in Python

import matplotlib.pyplot as pyplot

labels = ('Python', 'Java', 'Scala', 'C#')

sizes = [45, 30, 15, 10]

pyplot.pie(sizes,

labels=labels,

autopct='%1.f%%',

counterclock=False,

startangle=105)

# Display the figure

pyplot.show() 

#clcoding.com



# In[ ]:






# In[ ]:





Day 26 : Real time Currency Converter with Python

 



#!/usr/bin/env python

# coding: utf-8


# In[ ]:



pip install forex_python



# # Real-time Currency Converter with Python


# In[7]:



from forex_python.converter import CurrencyRates

c = CurrencyRates()

amount = int(input("Enter the amount: "))

from_currency = input("From Currency: ").upper()

to_currency = input("To Currency: ").upper()

print(from_currency, " To ", to_currency, amount)

result = c.convert(from_currency, to_currency, amount)

print(result)


#clcoding.com



# In[ ]:





Day 24 : Validate Anagrams using Python




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

# # Validate Anagrams using Python

# In[4]:


def anagram(word1, word2):
    word1 = word1.lower()
    word2 = word2.lower()
    return sorted(word1) == sorted(word2)

print(anagram("cinema", "iceman"))
print(anagram("cool", "loco"))
print(anagram("men", "women"))
print(anagram("python", "pythno"))
#clcoding.com


# In[ ]:






Day 23 : Contact Book in Python


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

# # Contact Book in Python

# In[1]:


names = []
phone_numbers = []
num = int(input("Enter no of contact you want to save : "))
for i in range(num):
    name = input("Name: ")
    phone_number = input("Phone Number: ") 
    names.append(name)
    phone_numbers.append(phone_number)
print("\nName\t\t\tPhone Number\n")
for i in range(num):
    print("{}\t\t\t{}".format(names[i], phone_numbers[i]))
search_term = input("\nEnter search term: ")
print("Search result:")
if search_term in names:
    index = names.index(search_term)
    phone_number = phone_numbers[index]
    print("Name: {}, Phone Number: {}".format(search_term, phone_number))
else: #clcoding.com
    print("Name Not Found")
    
#clcoding.com    


# In[ ]:






Day 22 : Pick a Random Card using Python

 



#!/usr/bin/env python

# coding: utf-8


# # Pick a Random Card using Python


# In[8]:



import random

cards = ["Diamonds", "Spades", "Hearts", "Clubs"]

ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10,

         "Jack", "Queen", "King", "Ace"]


def pick_a_card():

    card = random.choices(cards)

    rank = random.choices(ranks)

    return(f"The {rank} of {card}")


print(pick_a_card())


#clcoding.com



# In[ ]:





Day 21 : Fidget Spinner game with Python


 


#!/usr/bin/env python

# coding: utf-8


# # Fidget Spinner game with Python


# In[7]:



from turtle import *

state = {'turn': 0}

def spinner():

    clear()

    angle = state['turn']/10

    right(angle)

    forward(100)

    dot(120, 'cyan')

    back(100)

    right(120)

    forward(100)

    dot(120, 'green')

    back(100)

    right(120)

    forward(100)

    dot(120, 'blue')

    back(100)

    right(120)

    update()

def animate():

    if state['turn']>0:

        state['turn']-=1

    spinner() #clcoding.com

    ontimer(animate, 20)

def flick():

    state['turn']+=10

setup(420, 420, 370, 0)

hideturtle()

tracer(False)

width(20)

onkey(flick, 'space')

listen()

animate()

done()



# In[ ]:






# In[ ]:





Day 20 : Spelling Correction with Python





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

# In[ ]:


pip install textblob


# # Spelling Correction with Python

# In[28]:


from textblob import TextBlob
def Convert(string):
    li = list(string.split())
    return li  
str1 = input("Enter your word : ")
words=Convert(str1)
corrected_words = []
for i in words:
    corrected_words.append(TextBlob(i))
print("Wrong words :", words)
print("Corrected Words are :")
for i in corrected_words:
    print(i.correct(), end=" ")
#clcoding.com


# In[ ]:




Day 19 : Chessboard using Matplotlib in Python

 


#!/usr/bin/env python

# coding: utf-8


# # Chessboard using Matplotlib in Python


# In[17]:



import matplotlib.pyplot as plt

dx, dy = 0.015, 0.015

x = np.arange(-4.0, 4.0, dx)

y = np.arange(-4.0, 4.0, dy)

X, Y = np.meshgrid(x, y)

extent = np.min(x), np.max(x), np.min(y), np.max(y)

z1 = np.add.outer(range(8), range(8)) % 2

plt.imshow(z1, cmap="binary_r", interpolation="nearest", extent=extent, alpha=1)


def chess(x, y):

    return (1 - x / 2 + x ** 5 + y ** 6) * np.exp(-(x ** 2 + y ** 2))

z2 = chess(X, Y)

plt.imshow(z2, alpha=0, interpolation="bilinear", extent=extent)

plt.title("Chess Board in Python")

plt.show()

#clcoding.com



# In[ ]:





Day 18 : Three Dimensional contour plots



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

# # Three-Dimensional contour plots

# In[15]:


import numpy as np
import matplotlib.pyplot as plt
def f(x, y):
    return np.sin(np.sqrt(x ** 2 + y ** 2))
x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)
x, y = np.meshgrid(x, y)
z = f(x, y)              #clcoding.com
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.contour3D(x,y,z,50, cmap='binary')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_wireframe(x,y,z, color='black')
ax.set_title('wireframe')
plt.show()
ax = plt.axes(projection='3d')
ax.plot_surface(x, y, z, rstride=1,
                cstride=1, cmap='viridis',
                edgecolor='none')
ax.set_title('surface')
plt.show()


# In[ ]:




Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (112) C (77) C# (12) C++ (82) Course (60) Coursera (176) coursewra (1) Cybersecurity (22) data management (11) Data Science (85) 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 (18) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (43) Meta (18) MICHIGAN (4) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (719) Python Coding Challenge (155) 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