<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Arnab Dey</title>
    <description>The latest articles on DEV Community by Arnab Dey (@arnabdey).</description>
    <link>https://dev.to/arnabdey</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F398451%2Fe9de92cf-9a70-4f88-9b40-97f5c82f0d3b.jpg</url>
      <title>DEV Community: Arnab Dey</title>
      <link>https://dev.to/arnabdey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arnabdey"/>
    <language>en</language>
    <item>
      <title>Music Player App GUI using Python</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Mon, 31 May 2021 07:12:41 +0000</pubDate>
      <link>https://dev.to/arnabdey/music-player-app-gui-using-python-32ge</link>
      <guid>https://dev.to/arnabdey/music-player-app-gui-using-python-32ge</guid>
      <description>&lt;p&gt;Here, we will create a Music Player Application in Python using Pygame and Tkinter module.&lt;/p&gt;

&lt;p&gt;In our daily life, we see every person has a hobby and that is listening to music. So in order to listen to music, they all need a Music player(hardware or software) where they can play their favorite songs. And we have to install this music player on our computer, based the Operating system i.e Windows, Macintosh, Android, Linux, etc. Then we can listen to our favorite songs.&lt;/p&gt;

&lt;p&gt;Now we will help you to code and create a Music Player from scratch.&lt;/p&gt;

&lt;p&gt;Libraries used for Music Player Application:&lt;br&gt;
Now we will tell you about the Libraries we will use in our code :&lt;/p&gt;

&lt;p&gt;1.Tkinter&lt;/p&gt;

&lt;p&gt;We had already told you in the title of this page that we are going to use the Tkinter library, which is a standard library for GUI creation. The Tkinter library is most popular and very easy to use and it comes with many widgets (these widgets helps in the creation of nice-looking GUI Applications).&lt;/p&gt;

&lt;p&gt;Also, Tkinter is a very light-weight module and it is helpful in creating cross-platform applications(so the same code can easily work on Windows, macOS, and Linux)&lt;/p&gt;

&lt;p&gt;To use all the functions of Tkinter you need to import it in your code and the command for the same is:&lt;/p&gt;

&lt;p&gt;from tkinter import *&lt;/p&gt;

&lt;p&gt;2.Pygame module&lt;/p&gt;

&lt;p&gt;Pygame is a Python module that works with computer graphics and sound libraries and designed with the power of playing with different multimedia formats like audio, video, etc. While creating our Music Player application, we will be using Pygame's mixer.music module for providing different functionality to our music player application that is usually related to the manipulation of the song tracks.&lt;/p&gt;

&lt;p&gt;Command used to install pygame is:&lt;/p&gt;

&lt;p&gt;pip install pygame&lt;/p&gt;

&lt;p&gt;Click and drag to moveTo use this module into your code you need to write this:&lt;/p&gt;

&lt;p&gt;import pygame&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;OS module&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There is no need to install this module explicitly, as it comes with the standard library of Python. This module provides different functions for interaction with the Operating System. In this tutorial, we are going to use the OS module for fetching the playlist of songs from the specified directory and make it available to the music player application.&lt;/p&gt;

&lt;p&gt;To use this module in your code you need to import its and command for the same is as follows:&lt;/p&gt;

&lt;p&gt;import OS&lt;/p&gt;

&lt;p&gt;After importing Libraries and modules, now it's time to create a basic window where we will add our UI elements or Tkinter widgets. You can add this code either after importing libraries or also at the end just before the looping of the root window and the code is as follows:&lt;/p&gt;

&lt;p&gt;root = Tk() # In order to create an empty window&lt;/p&gt;

&lt;h1&gt;
  
  
  Passing Root to MusicPlayer Class
&lt;/h1&gt;

&lt;p&gt;MusicPlayer(root)&lt;br&gt;
MusicPlayer Class&lt;br&gt;
Here we have the constructor and the other functions defined in the MusicPlayer class.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;init&lt;/em&gt; Constructor
With the help of this constructor, we will set the title for the window and geometry for the window. We will initiate pygame and pygame mixer and then declare track variable and status variable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We will then Create the Track Frames for Song label &amp;amp; status label and then after Insert the Song Track Label and Status Label.&lt;/p&gt;

&lt;p&gt;After that, we will create the Button Frame and insert play, pause, unpause, and stop buttons into it.&lt;/p&gt;

&lt;p&gt;Then we will create the playlist frame and add the scrollbar to it and we will add songs into playlist.&lt;/p&gt;

&lt;p&gt;The code snippet is as follows:&lt;/p&gt;

&lt;p&gt;def &lt;strong&gt;init&lt;/strong&gt;(self,root):&lt;br&gt;
    self.root = root&lt;br&gt;
    # Title of the window&lt;br&gt;
    self.root.title("MusicPlayer")&lt;br&gt;
    # Window Geometry&lt;br&gt;
    self.root.geometry("1000x200+200+200")&lt;br&gt;
    # Initiating Pygame&lt;br&gt;
    pygame.init()&lt;br&gt;
    # Initiating Pygame Mixer&lt;br&gt;
    pygame.mixer.init()&lt;br&gt;
    # Declaring track Variable&lt;br&gt;
    self.track = StringVar()&lt;br&gt;
    # Declaring Status Variable&lt;br&gt;
    self.status = StringVar()&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Creating the Track Frames for Song label &amp;amp; status label
trackframe = LabelFrame(self.root,text="Song Track",font=("times new roman",15,"bold"),bg="Navyblue",fg="white",bd=5,relief=GROOVE)
trackframe.place(x=0,y=0,width=600,height=100)
# Inserting Song Track Label
songtrack = Label(trackframe,textvariable=self.track,width=20,font=("times new roman",24,"bold"),bg="Orange",fg="gold").grid(row=0,column=0,padx=10,pady=5)
# Inserting Status Label
trackstatus = Label(trackframe,textvariable=self.status,font=("times new roman",24,"bold"),bg="orange",fg="gold").grid(row=0,column=1,padx=10,pady=5)

# Creating Button Frame
buttonframe = LabelFrame(self.root,text="Control Panel",font=("times new roman",15,"bold"),bg="grey",fg="white",bd=5,relief=GROOVE)
buttonframe.place(x=0,y=100,width=600,height=100)
# Inserting Play Button
playbtn = Button(buttonframe,text="PLAYSONG",command=self.playsong,width=10,height=1,font=("times new roman",16,"bold"),fg="navyblue",bg="pink").grid(row=0,column=0,padx=10,pady=5)
# Inserting Pause Button
playbtn = Button(buttonframe,text="PAUSE",command=self.pausesong,width=8,height=1,font=("times new roman",16,"bold"),fg="navyblue",bg="pink").grid(row=0,column=1,padx=10,pady=5)
# Inserting Unpause Button
playbtn = Button(buttonframe,text="UNPAUSE",command=self.unpausesong,width=10,height=1,font=("times new roman",16,"bold"),fg="navyblue",bg="pink").grid(row=0,column=2,padx=10,pady=5)
# Inserting Stop Button
playbtn = Button(buttonframe,text="STOPSONG",command=self.stopsong,width=10,height=1,font=("times new roman",16,"bold"),fg="navyblue",bg="pink").grid(row=0,column=3,padx=10,pady=5)

# Creating Playlist Frame
songsframe = LabelFrame(self.root,text="Song Playlist",font=("times new roman",15,"bold"),bg="grey",fg="white",bd=5,relief=GROOVE)
songsframe.place(x=600,y=0,width=400,height=200)
# Inserting scrollbar
scrol_y = Scrollbar(songsframe,orient=VERTICAL)
# Inserting Playlist listbox
self.playlist = Listbox(songsframe,yscrollcommand=scrol_y.set,selectbackground="gold",selectmode=SINGLE,font=("times new roman",12,"bold"),bg="silver",fg="navyblue",bd=5,relief=GROOVE)
# Applying Scrollbar to listbox
scrol_y.pack(side=RIGHT,fill=Y)
scrol_y.config(command=self.playlist.yview)
self.playlist.pack(fill=BOTH)
# Changing Directory for fetching Songs
os.chdir("PATH/OF/DIRECTORY")
# Fetching Songs
songtracks = os.listdir()
# Inserting Songs into Playlist
for track in songtracks:
  self.playlist.insert(END,track)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code above, change the PATH/OF/DIRECTORY with appropriate path where the song files are stored.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The playsong() Function
Now we will define the Play Song Function and the code is:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;def playsong(self):&lt;br&gt;
    # Displaying Selected Song title&lt;br&gt;
    self.track.set(self.playlist.get(ACTIVE))&lt;br&gt;
    # Displaying Status&lt;br&gt;
    self.status.set("-Playing")&lt;br&gt;
    # Loading Selected Song&lt;br&gt;
    pygame.mixer.music.load(self.playlist.get(ACTIVE))&lt;br&gt;
    # Playing Selected Song&lt;br&gt;
    pygame.mixer.music.play()&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The stopsong() Function
The code snippet to stop the song:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;def stopsong(self):&lt;br&gt;
    # Displaying Status&lt;br&gt;
    self.status.set("-Stopped")&lt;br&gt;
    # Stopped Song&lt;br&gt;
    pygame.mixer.music.stop()&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The pausesong() Function
The code snippet to pause the song:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;def pausesong(self):&lt;br&gt;
    # Displaying Status&lt;br&gt;
    self.status.set("-Paused")&lt;br&gt;
    # Paused Song&lt;br&gt;
    pygame.mixer.music.pause()&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The unpausesong() Function
The code snippet to unpause the song:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;def unpausesong(self):&lt;br&gt;
    # It will Display the  Status&lt;br&gt;
    self.status.set("-Playing")&lt;br&gt;
    # Playing back Song&lt;br&gt;
    pygame.mixer.music.unpause()&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Root Window Looping
The command will be:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;root.mainloop()&lt;br&gt;
Now here are some of the screenshots of our application:&lt;/p&gt;

&lt;p&gt;We will provide the path of the songs folder in our code where all songs are placed in order to access them.&lt;/p&gt;

&lt;p&gt;Now the following screenshot is to show you how the application will look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zJWvCGyl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4sxntv5jgkbzevucu4qu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zJWvCGyl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4sxntv5jgkbzevucu4qu.png" alt="image" width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;whenever you made a click on the song it will look like:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wx47lmNA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pd9khs45007psufoqwu5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wx47lmNA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pd9khs45007psufoqwu5.png" alt="image" width="800" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On clicking the PLAYSONG Button:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jQ0B4_4Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ktofhlo989c4d061j2q1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jQ0B4_4Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ktofhlo989c4d061j2q1.png" alt="image" width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On clicking the PAUSE Button:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AzwHeSsL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4aroq6fc3b4drjnle9k2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AzwHeSsL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4aroq6fc3b4drjnle9k2.png" alt="image" width="800" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On clicking the STOP Button:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5F-PV5W---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/niqyhkq7agtfarng7dla.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5F-PV5W---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/niqyhkq7agtfarng7dla.png" alt="image" width="800" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So this was all about building the Music Player Application using Tkinter. Hope you all like this application. &lt;/p&gt;

</description>
      <category>python</category>
      <category>codenewbie</category>
      <category>tutorial</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Calculator Application GUI using Python</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Mon, 31 May 2021 06:46:28 +0000</pubDate>
      <link>https://dev.to/arnabdey/calculator-application-gui-using-python-53m9</link>
      <guid>https://dev.to/arnabdey/calculator-application-gui-using-python-53m9</guid>
      <description>&lt;h1&gt;
  
  
  What is a Calculator?
&lt;/h1&gt;

&lt;p&gt;For those who do not know, a calculator is basically a program on a computer that simulates the behavior of any hand-held calculator useful for performing Mathematical Calculations. It is a very basic device used in our every day lives. Now all the smartphones also have a Calculator application in them.&lt;/p&gt;

&lt;p&gt;While creating any GUI Application there are mainly two steps:&lt;/p&gt;

&lt;p&gt;The first step is to create a User Interface.&lt;/p&gt;

&lt;p&gt;The second step is the most important one and in this, to add functionalities to the GUI&lt;/p&gt;

&lt;p&gt;Now let's begin with creating a simple calculator app using Tkinter in Python which is used for basic arithmetic calculations.&lt;/p&gt;

&lt;p&gt;Calculator App Code&lt;/p&gt;

&lt;p&gt;Now it's time to take a look at the code to create a Calculator App using Tkinter.&lt;/p&gt;

&lt;p&gt;Here is how our calculator will look, which is made by using the input field, buttons and for the calculation purpose we will use logic in our code defined in functions, like if you want to add two numbers then behind this there must be a logic for addition purpose, similarly for substraction, multiplication, etc, we have created functions whose task is to perform these operations.&lt;/p&gt;

&lt;p&gt;Now we will show you a snapshot as the output of the above code. And yes you can implement it on your system for more clear.&lt;/p&gt;

&lt;h1&gt;
  
  
  Understanding of Calculator App Using Tkinter:
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j5lgoyZI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6730vfb3p9hqwecykfw3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j5lgoyZI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6730vfb3p9hqwecykfw3.png" alt="image" width="306" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have an Input Field in which the user input will be shown and the final result of the calculation will be displayed.&lt;/p&gt;

&lt;p&gt;And the buttons are like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, -, *, /, =, ., and C(clear button)&lt;/p&gt;

&lt;p&gt;There are a variety of functions in Tkinter with the help of them it becomes easy and convenient to make a simple calculator just with this little code.&lt;/p&gt;

&lt;h1&gt;
  
  
  Calcular Application GUI using Python Code
&lt;/h1&gt;

&lt;p&gt;from tkinter import *&lt;/p&gt;

&lt;p&gt;win = Tk() # This is to create a basic window&lt;br&gt;
win.geometry("312x324")  # this is for the size of the window &lt;br&gt;
win.resizable(0, 0)  # this is to prevent from resizing the window&lt;br&gt;
win.title("Calculator")&lt;/p&gt;

&lt;h6&gt;
  
  
  #############Starting with functions
&lt;/h6&gt;

&lt;h1&gt;
  
  
  'btn_click' function :
&lt;/h1&gt;

&lt;h1&gt;
  
  
  This Function continuously updates the
&lt;/h1&gt;

&lt;h1&gt;
  
  
  input field whenever you enters a number
&lt;/h1&gt;

&lt;p&gt;def btn_click(item):&lt;br&gt;
    global expression&lt;br&gt;
    expression = expression + str(item)&lt;br&gt;
    input_text.set(expression)&lt;/p&gt;

&lt;h1&gt;
  
  
  'bt_clear' function :This is used to clear
&lt;/h1&gt;

&lt;h1&gt;
  
  
  the input field
&lt;/h1&gt;

&lt;p&gt;def bt_clear(): &lt;br&gt;
    global expression &lt;br&gt;
    expression = "" &lt;br&gt;
    input_text.set("")&lt;/p&gt;

&lt;h1&gt;
  
  
  'bt_equal':This method calculates the expression
&lt;/h1&gt;

&lt;h1&gt;
  
  
  present in input field
&lt;/h1&gt;

&lt;p&gt;def bt_equal():&lt;br&gt;
    global expression&lt;br&gt;
    result = str(eval(expression)) # 'eval':This function is used to evaluates the string expression directly&lt;br&gt;
    input_text.set(result)&lt;br&gt;
    expression = ""&lt;/p&gt;

&lt;p&gt;expression = ""&lt;/p&gt;

&lt;h1&gt;
  
  
  'StringVar()' :It is used to get the instance of input field
&lt;/h1&gt;

&lt;p&gt;input_text = StringVar()&lt;/p&gt;

&lt;h1&gt;
  
  
  Let us creating a frame for the input field
&lt;/h1&gt;

&lt;p&gt;input_frame = Frame(win, width=312, height=50, bd=0, highlightbackground="black", highlightcolor="black", highlightthickness=2)&lt;/p&gt;

&lt;p&gt;input_frame.pack(side=TOP)&lt;/p&gt;

&lt;h1&gt;
  
  
  Let us create a input field inside the 'Frame'
&lt;/h1&gt;

&lt;p&gt;input_field = Entry(input_frame, font=('arial', 18, 'bold'), textvariable=input_text, width=50, bg="#eee", bd=0, justify=RIGHT)&lt;/p&gt;

&lt;p&gt;input_field.grid(row=0, column=0)&lt;/p&gt;

&lt;p&gt;input_field.pack(ipady=10) # 'ipady' is internal padding to increase the height of input field&lt;/p&gt;

&lt;h1&gt;
  
  
  Let us creating another 'Frame' for the button below the 'input_frame'
&lt;/h1&gt;

&lt;p&gt;btns_frame = Frame(win, width=312, height=272.5, bg="grey")&lt;/p&gt;

&lt;p&gt;btns_frame.pack()&lt;/p&gt;

&lt;h1&gt;
  
  
  first row
&lt;/h1&gt;

&lt;p&gt;clear = Button(btns_frame, text = "C", fg = "black", width = 32, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: bt_clear()).grid(row = 0, column = 0, columnspan = 3, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;divide = Button(btns_frame, text = "/", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("/")).grid(row = 0, column = 3, padx = 1, pady = 1)&lt;/p&gt;

&lt;h1&gt;
  
  
  second row
&lt;/h1&gt;

&lt;p&gt;seven = Button(btns_frame, text = "7", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(7)).grid(row = 1, column = 0, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;eight = Button(btns_frame, text = "8", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(8)).grid(row = 1, column = 1, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;nine = Button(btns_frame, text = "9", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(9)).grid(row = 1, column = 2, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;multiply = Button(btns_frame, text = "&lt;em&gt;", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("&lt;/em&gt;")).grid(row = 1, column = 3, padx = 1, pady = 1)&lt;/p&gt;

&lt;h1&gt;
  
  
  third row
&lt;/h1&gt;

&lt;p&gt;four = Button(btns_frame, text = "4", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(4)).grid(row = 2, column = 0, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;five = Button(btns_frame, text = "5", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(5)).grid(row = 2, column = 1, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;six = Button(btns_frame, text = "6", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(6)).grid(row = 2, column = 2, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;minus = Button(btns_frame, text = "-", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("-")).grid(row = 2, column = 3, padx = 1, pady = 1)&lt;/p&gt;

&lt;h1&gt;
  
  
  fourth row
&lt;/h1&gt;

&lt;p&gt;one = Button(btns_frame, text = "1", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(1)).grid(row = 3, column = 0, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;two = Button(btns_frame, text = "2", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(2)).grid(row = 3, column = 1, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;three = Button(btns_frame, text = "3", fg = "black", width = 10, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(3)).grid(row = 3, column = 2, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;plus = Button(btns_frame, text = "+", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("+")).grid(row = 3, column = 3, padx = 1, pady = 1)&lt;/p&gt;

&lt;h1&gt;
  
  
  fourth row
&lt;/h1&gt;

&lt;p&gt;zero = Button(btns_frame, text = "0", fg = "black", width = 21, height = 3, bd = 0, bg = "#fff", cursor = "hand2", command = lambda: btn_click(0)).grid(row = 4, column = 0, columnspan = 2, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;point = Button(btns_frame, text = ".", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click(".")).grid(row = 4, column = 2, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;equals = Button(btns_frame, text = "=", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: bt_equal()).grid(row = 4, column = 3, padx = 1, pady = 1)&lt;/p&gt;

&lt;p&gt;win.mainloop()&lt;/p&gt;

&lt;p&gt;Github Link: &lt;a href="https://github.com/arnab132/Calculator-Application-GUI-Python"&gt;https://github.com/arnab132/Calculator-Application-GUI-Python&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>github</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>JavaScript Cookies</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Mon, 31 May 2021 02:48:05 +0000</pubDate>
      <link>https://dev.to/arnabdey/javascript-cookies-35lk</link>
      <guid>https://dev.to/arnabdey/javascript-cookies-35lk</guid>
      <description>&lt;p&gt;Cookies let you store user information in web pages.&lt;/p&gt;

&lt;p&gt;What are Cookies?&lt;br&gt;
Cookies are data, stored in small text files, on your computer.&lt;/p&gt;

&lt;p&gt;When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user.&lt;/p&gt;

&lt;p&gt;Cookies were invented to solve the problem "how to remember information about the user":&lt;/p&gt;

&lt;p&gt;When a user visits a web page, his/her name can be stored in a cookie.&lt;br&gt;
Next time the user visits the page, the cookie "remembers" his/her name.&lt;br&gt;
Cookies are saved in name-value pairs like:&lt;/p&gt;

&lt;p&gt;username = John Doe&lt;br&gt;
When a browser requests a web page from a server, cookies belonging to the page are added to the request. This way the server gets the necessary data to "remember" information about users.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DCJJCuj3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdr8ssbjw9z5lusn4wtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DCJJCuj3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdr8ssbjw9z5lusn4wtg.png" alt="image" width="600" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: None of the examples below will work if your browser has local cookies support turned off.&lt;/p&gt;

&lt;h1&gt;
  
  
  Create a Cookie with JavaScript
&lt;/h1&gt;

&lt;p&gt;JavaScript can create, read, and delete cookies with the document.cookie property.&lt;/p&gt;

&lt;p&gt;With JavaScript, a cookie can be created like this:&lt;/p&gt;

&lt;p&gt;document.cookie = "username=John Doe";&lt;/p&gt;

&lt;p&gt;You can also add an expiry date (in UTC time). By default, the cookie is deleted when the browser is closed:&lt;/p&gt;

&lt;p&gt;document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC";&lt;br&gt;
With a path parameter, you can tell the browser what path the cookie belongs to. By default, the cookie belongs to the current page.&lt;/p&gt;

&lt;p&gt;document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";&lt;br&gt;
Read a Cookie with JavaScript&lt;br&gt;
With JavaScript, cookies can be read like this:&lt;/p&gt;

&lt;p&gt;var x = document.cookie;&lt;br&gt;
document.cookie will return all cookies in one string much like: cookie1=value; cookie2=value; cookie3=value;&lt;/p&gt;

&lt;h1&gt;
  
  
  Change a Cookie with JavaScript
&lt;/h1&gt;

&lt;p&gt;With JavaScript, you can change a cookie the same way as you create it:&lt;/p&gt;

&lt;p&gt;document.cookie = "username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";&lt;br&gt;
The old cookie is overwritten.&lt;/p&gt;

&lt;h1&gt;
  
  
  Delete a Cookie with JavaScript
&lt;/h1&gt;

&lt;p&gt;Deleting a cookie is very simple.&lt;/p&gt;

&lt;p&gt;You don't have to specify a cookie value when you delete a cookie.&lt;/p&gt;

&lt;p&gt;Just set the expires parameter to a past date:&lt;/p&gt;

&lt;p&gt;document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";&lt;br&gt;
You should define the cookie path to ensure that you delete the right cookie.&lt;/p&gt;

&lt;p&gt;Some browsers will not let you delete a cookie if you don't specify the path.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Cookie String
&lt;/h1&gt;

&lt;p&gt;The document.cookie property looks like a normal text string. But it is not.&lt;/p&gt;

&lt;p&gt;Even if you write a whole cookie string to document.cookie, when you read it out again, you can only see the name-value pair of it.&lt;/p&gt;

&lt;p&gt;If you set a new cookie, older cookies are not overwritten. The new cookie is added to document.cookie, so if you read document.cookie again you will get something like:&lt;/p&gt;

&lt;p&gt;cookie1 = value; cookie2 = value;&lt;/p&gt;

&lt;p&gt;Display All Cookies  Create Cookie 1  Create Cookie 2 Delete Cookie 1  Delete Cookie 2&lt;/p&gt;

&lt;p&gt;If you want to find the value of one specified cookie, you must write a JavaScript function that searches for the cookie value in the cookie string.&lt;/p&gt;

&lt;h1&gt;
  
  
  JavaScript Cookie Example
&lt;/h1&gt;

&lt;p&gt;In the example to follow, we will create a cookie that stores the name of a visitor.&lt;/p&gt;

&lt;p&gt;The first time a visitor arrives to the web page, he/she will be asked to fill in his/her name. The name is then stored in a cookie.&lt;/p&gt;

&lt;p&gt;The next time the visitor arrives at the same page, he/she will get a welcome message.&lt;/p&gt;

&lt;p&gt;For the example we will create 3 JavaScript functions:&lt;/p&gt;

&lt;p&gt;A function to set a cookie value&lt;br&gt;
A function to get a cookie value&lt;br&gt;
A function to check a cookie value&lt;br&gt;
A Function to Set a Cookie&lt;/p&gt;

&lt;p&gt;First, we create a function that stores the name of the visitor in a cookie variable:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
function setCookie(cname, cvalue, exdays) {&lt;br&gt;
  var d = new Date();&lt;br&gt;
  d.setTime(d.getTime() + (exdays*24*60*60*1000));&lt;br&gt;
  var expires = "expires="+ d.toUTCString();&lt;br&gt;
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";&lt;br&gt;
}&lt;br&gt;
Example explained:&lt;/p&gt;

&lt;p&gt;The parameters of the function above are the name of the cookie (cname), the value of the cookie (cvalue), and the number of days until the cookie should expire (exdays).&lt;/p&gt;

&lt;p&gt;The function sets a cookie by adding together the cookiename, the cookie value, and the expires string.&lt;/p&gt;

&lt;p&gt;A Function to Get a Cookie&lt;br&gt;
Then, we create a function that returns the value of a specified cookie:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
function getCookie(cname) {&lt;br&gt;
  var name = cname + "=";&lt;br&gt;
  var decodedCookie = decodeURIComponent(document.cookie);&lt;br&gt;
  var ca = decodedCookie.split(';');&lt;br&gt;
  for(var i = 0; i &amp;lt;ca.length; i++) {&lt;br&gt;
    var c = ca[i];&lt;br&gt;
    while (c.charAt(0) == ' ') {&lt;br&gt;
      c = c.substring(1);&lt;br&gt;
    }&lt;br&gt;
    if (c.indexOf(name) == 0) {&lt;br&gt;
      return c.substring(name.length, c.length);&lt;br&gt;
    }&lt;br&gt;
  }&lt;br&gt;
  return "";&lt;br&gt;
}&lt;br&gt;
Function explained:&lt;/p&gt;

&lt;p&gt;Take the cookiename as parameter (cname).&lt;/p&gt;

&lt;p&gt;Create a variable (name) with the text to search for (cname + "=").&lt;/p&gt;

&lt;p&gt;Decode the cookie string, to handle cookies with special characters, e.g. '$'&lt;/p&gt;

&lt;p&gt;Split document.cookie on semicolons into an array called ca (ca = decodedCookie.split(';')).&lt;/p&gt;

&lt;p&gt;Loop through the ca array (i = 0; i &amp;lt; ca.length; i++), and read out each value c = ca[i]).&lt;/p&gt;

&lt;p&gt;If the cookie is found (c.indexOf(name) == 0), return the value of the cookie (c.substring(name.length, c.length).&lt;/p&gt;

&lt;p&gt;If the cookie is not found, return "".&lt;/p&gt;

&lt;p&gt;A Function to Check a Cookie&lt;br&gt;
Last, we create the function that checks if a cookie is set.&lt;/p&gt;

&lt;p&gt;If the cookie is set it will display a greeting.&lt;/p&gt;

&lt;p&gt;If the cookie is not set, it will display a prompt box, asking for the name of the user, and stores the username cookie for 365 days, by calling the setCookie function:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
function checkCookie() {&lt;br&gt;
  var username = getCookie("username");&lt;br&gt;
  if (username != "") {&lt;br&gt;
   alert("Welcome again " + username);&lt;br&gt;
  } else {&lt;br&gt;
    username = prompt("Please enter your name:", "");&lt;br&gt;
    if (username != "" &amp;amp;&amp;amp; username != null) {&lt;br&gt;
      setCookie("username", username, 365);&lt;br&gt;
    }&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

&lt;h1&gt;
  
  
  All Together Lets See
&lt;/h1&gt;

&lt;p&gt;Example&lt;br&gt;
function setCookie(cname, cvalue, exdays) {&lt;br&gt;
  var d = new Date();&lt;br&gt;
  d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));&lt;br&gt;
  var expires = "expires="+d.toUTCString();&lt;br&gt;
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function getCookie(cname) {&lt;br&gt;
  var name = cname + "=";&lt;br&gt;
  var ca = document.cookie.split(';');&lt;br&gt;
  for(var i = 0; i &amp;lt; ca.length; i++) {&lt;br&gt;
    var c = ca[i];&lt;br&gt;
    while (c.charAt(0) == ' ') {&lt;br&gt;
      c = c.substring(1);&lt;br&gt;
    }&lt;br&gt;
    if (c.indexOf(name) == 0) {&lt;br&gt;
      return c.substring(name.length, c.length);&lt;br&gt;
    }&lt;br&gt;
  }&lt;br&gt;
  return "";&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function checkCookie() {&lt;br&gt;
  var user = getCookie("username");&lt;br&gt;
  if (user != "") {&lt;br&gt;
    alert("Welcome again " + user);&lt;br&gt;
  } else {&lt;br&gt;
    user = prompt("Please enter your name:", "");&lt;br&gt;
    if (user != "" &amp;amp;&amp;amp; user != null) {&lt;br&gt;
      setCookie("username", user, 365);&lt;br&gt;
    }&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Popup boxes Tutorial</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Mon, 31 May 2021 02:44:21 +0000</pubDate>
      <link>https://dev.to/arnabdey/javascript-popup-boxes-tutorial-de6</link>
      <guid>https://dev.to/arnabdey/javascript-popup-boxes-tutorial-de6</guid>
      <description>&lt;p&gt;JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.&lt;/p&gt;

&lt;p&gt;Alert Box&lt;br&gt;
An alert box is often used if you want to make sure information comes through to the user.&lt;/p&gt;

&lt;p&gt;When an alert box pops up, the user will have to click "OK" to proceed.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
window.alert("sometext");&lt;/p&gt;

&lt;p&gt;The window.alert() method can be written without the window prefix.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
alert("I am an alert box!");&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---dFtMse5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05h0o42p8wsqhqnef96d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---dFtMse5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05h0o42p8wsqhqnef96d.png" alt="image" width="510" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Confirm Box&lt;br&gt;
A confirm box is often used if you want the user to verify or accept something.&lt;/p&gt;

&lt;p&gt;When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.&lt;/p&gt;

&lt;p&gt;If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
window.confirm("sometext");&lt;/p&gt;

&lt;p&gt;The window.confirm() method can be written without the window prefix.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
if (confirm("Press a button!")) {&lt;br&gt;
  txt = "You pressed OK!";&lt;br&gt;
} else {&lt;br&gt;
  txt = "You pressed Cancel!";&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Prompt Box&lt;br&gt;
A prompt box is often used if you want the user to input a value before entering a page.&lt;/p&gt;

&lt;p&gt;When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value.&lt;/p&gt;

&lt;p&gt;If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
window.prompt("sometext","defaultText");&lt;br&gt;
The window.prompt() method can be written without the window prefix.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
var person = prompt("Please enter your name", "Harry Potter");&lt;/p&gt;

&lt;p&gt;if (person == null || person == "") {&lt;br&gt;
  txt = "User cancelled the prompt.";&lt;br&gt;
} else {&lt;br&gt;
  txt = "Hello " + person + "! How are you today?";&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7QZ-tYnl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zhkts27jjk3683m96ye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7QZ-tYnl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zhkts27jjk3683m96ye.png" alt="image" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Line Breaks&lt;br&gt;
To display line breaks inside a popup box, use a back-slash followed by the character n.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
alert("Hello\nHow are you?");&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Balloon Shooter Game Using Python</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Mon, 31 May 2021 02:20:28 +0000</pubDate>
      <link>https://dev.to/arnabdey/balloon-shooter-game-using-python-3p7k</link>
      <guid>https://dev.to/arnabdey/balloon-shooter-game-using-python-3p7k</guid>
      <description>&lt;h1&gt;
  
  
  Balloon Shooter
&lt;/h1&gt;

&lt;p&gt;Balloon shooting is a simple archery game or Balloon smasher game. Balloon bursting game has simple rules but require great skill of shooting. Balloon popping or balloon shooting is best game to play in your leisure time. This game is similar to classic Bubble breaker or bubble pop game. You will get limited arrows to shoot the balloons and you have to utilize it in best possible way to score high by bursting the balloons. The smaller the balloon you shoot, more the score you get. The objective of this balloon shooting game is to pop as many balloons as possible using as few arrows as possible. You can shoot multiple balloons with one arrow as well, make best use of your arrows to shoot multiple balloons coming in line. In this game a lot of options are available to score more with special balloons coming in the way like balloon with bomb, 3 balloons at a time, wheels and small balloon. It all depends on your shooting skill and logical thinking how you can score more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CY5-RuiD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7r0f48zfn5ct4rh6xgq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CY5-RuiD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7r0f48zfn5ct4rh6xgq.png" alt="image" width="512" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This fun learning game is all time favourite among kids and adults. Rule of Balloon shooting game is simple and fun is never less, game still remains challenging. Show your mastery in this amazing game by pulling the rope and adjusting the angle of arrows to shoot maximum balloons in one shot, aim carefully. Multiply your scores by aiming at multiple balloons with one shot. It is like sniper games where the bullets are replaced with bundles of arrows, and you get a predictable, physics-based ricochet effect. Balloons of all colors, shapes and sizes are coming down your way. Prepare your strategy and become master in balloon shooting.&lt;/p&gt;

&lt;p&gt;Be warned this addictive game is hard to stop. It is very intuitive and easy to learn but you need to master it to score high. Amazing graphics, interesting sound effects and smooth animation spices up the entertainment in the game. Compile this interesting game and let the fun begin.&lt;/p&gt;

&lt;h1&gt;
  
  
  Let us learn how to develop balloon shooting game and its technique with Pygame
&lt;/h1&gt;

&lt;h1&gt;
  
  
  ------------------------------------
&lt;/h1&gt;

&lt;p&gt;Balloon Shooter&lt;br&gt;
Language - Python&lt;br&gt;
Modules - pygame, sys, random, math &lt;br&gt;
Controls - Mouse&lt;br&gt;
By - Arnab Dey&lt;/p&gt;

&lt;h1&gt;
  
  
  ------------------------------------
&lt;/h1&gt;

&lt;p&gt;import pygame&lt;br&gt;
import sys&lt;br&gt;
import random&lt;br&gt;
from math import *&lt;/p&gt;

&lt;p&gt;pygame.init()&lt;/p&gt;

&lt;p&gt;width = 500&lt;br&gt;
height = 500&lt;/p&gt;

&lt;p&gt;display = pygame.display.set_mode((width, height))&lt;br&gt;
pygame.display.set_caption("Balloon Shooter")&lt;br&gt;
clock = pygame.time.Clock()&lt;/p&gt;

&lt;p&gt;margin = 100&lt;br&gt;
lowerBound = 100&lt;/p&gt;

&lt;p&gt;score = 0&lt;/p&gt;

&lt;h1&gt;
  
  
  Colors
&lt;/h1&gt;

&lt;p&gt;white = (230, 230, 230)&lt;br&gt;
lightBlue = (174, 214, 241)&lt;br&gt;
red = (231, 76, 60)&lt;br&gt;
lightGreen = (25, 111, 61)&lt;br&gt;
darkGray = (40, 55, 71)&lt;br&gt;
darkBlue = (21, 67, 96)&lt;br&gt;
green = (35, 155, 86)&lt;br&gt;
yellow = (244, 208, 63)&lt;br&gt;
blue = (46, 134, 193)&lt;br&gt;
purple = (155, 89, 182)&lt;br&gt;
orange = (243, 156, 18)&lt;/p&gt;

&lt;p&gt;font = pygame.font.SysFont("Snap ITC", 25)&lt;/p&gt;

&lt;h1&gt;
  
  
  Balloon Class
&lt;/h1&gt;

&lt;p&gt;class Balloon:&lt;br&gt;
    def &lt;strong&gt;init&lt;/strong&gt;(self, speed):&lt;br&gt;
        self.a = random.randint(30, 40)&lt;br&gt;
        self.b = self.a + random.randint(0, 10)&lt;br&gt;
        self.x = random.randrange(margin, width - self.a - margin)&lt;br&gt;
        self.y = height - lowerBound&lt;br&gt;
        self.angle = 90&lt;br&gt;
        self.speed = -speed&lt;br&gt;
        self.probPool = [-1, -1, -1, 0, 0, 0, 0, 1, 1, 1]&lt;br&gt;
        self.length = random.randint(50, 100)&lt;br&gt;
        self.color = random.choice([red, green, purple, orange, yellow, blue])&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Move balloon around the Screen
def move(self):
    direct = random.choice(self.probPool)

    if direct == -1:
        self.angle += -10
    elif direct == 0:
        self.angle += 0
    else:
        self.angle += 10

    self.y += self.speed*sin(radians(self.angle))
    self.x += self.speed*cos(radians(self.angle))

    if (self.x + self.a &amp;gt; width) or (self.x &amp;lt; 0):
        if self.y &amp;gt; height/5:
            self.x -= self.speed*cos(radians(self.angle)) 
        else:
            self.reset()
    if self.y + self.b &amp;lt; 0 or self.y &amp;gt; height + 30:
        self.reset()

# Show/Draw the balloon  
def show(self):
    pygame.draw.line(display, darkBlue, (self.x + self.a/2, self.y + self.b), (self.x + self.a/2, self.y + self.b + self.length))
    pygame.draw.ellipse(display, self.color, (self.x, self.y, self.a, self.b))
    pygame.draw.ellipse(display, self.color, (self.x + self.a/2 - 5, self.y + self.b - 3, 10, 10))

# Check if Balloon is bursted
def burst(self):
    global score
    pos = pygame.mouse.get_pos()

    if onBalloon(self.x, self.y, self.a, self.b, pos):
        score += 1
        self.reset()

# Reset the Balloon
def reset(self):
    self.a = random.randint(30, 40)
    self.b = self.a + random.randint(0, 10)
    self.x = random.randrange(margin, width - self.a - margin)
    self.y = height - lowerBound 
    self.angle = 90
    self.speed -= 0.002
    self.probPool = [-1, -1, -1, 0, 0, 0, 0, 1, 1, 1]
    self.length = random.randint(50, 100)
    self.color = random.choice([red, green, purple, orange, yellow, blue])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;balloons = []&lt;br&gt;
noBalloon = 10&lt;br&gt;
for i in range(noBalloon):&lt;br&gt;
    obj = Balloon(random.choice([1, 1, 2, 2, 2, 2, 3, 3, 3, 4]))&lt;br&gt;
    balloons.append(obj)&lt;/p&gt;

&lt;p&gt;def onBalloon(x, y, a, b, pos):&lt;br&gt;
    if (x &amp;lt; pos[0] &amp;lt; x + a) and (y &amp;lt; pos[1] &amp;lt; y + b):&lt;br&gt;
        return True&lt;br&gt;
    else:&lt;br&gt;
        return False&lt;/p&gt;

&lt;h1&gt;
  
  
  show the location of Mouse
&lt;/h1&gt;

&lt;p&gt;def pointer():&lt;br&gt;
    pos = pygame.mouse.get_pos()&lt;br&gt;
    r = 25&lt;br&gt;
    l = 20&lt;br&gt;
    color = lightGreen&lt;br&gt;
    for i in range(noBalloon):&lt;br&gt;
        if onBalloon(balloons[i].x, balloons[i].y, balloons[i].a, balloons[i].b, pos):&lt;br&gt;
            color = red&lt;br&gt;
    pygame.draw.ellipse(display, color, (pos[0] - r/2, pos[1] - r/2, r, r), 4)&lt;br&gt;
    pygame.draw.line(display, color, (pos[0], pos[1] - l/2), (pos[0], pos[1] - l), 4)&lt;br&gt;
    pygame.draw.line(display, color, (pos[0] + l/2, pos[1]), (pos[0] + l, pos[1]), 4)&lt;br&gt;
    pygame.draw.line(display, color, (pos[0], pos[1] + l/2), (pos[0], pos[1] + l), 4)&lt;br&gt;
    pygame.draw.line(display, color, (pos[0] - l/2, pos[1]), (pos[0] - l, pos[1]), 4)&lt;/p&gt;

&lt;p&gt;def lowerPlatform():&lt;br&gt;
    pygame.draw.rect(display, darkGray, (0, height - lowerBound, width, lowerBound))&lt;/p&gt;

&lt;p&gt;def showScore():&lt;br&gt;
    scoreText = font.render("Balloons Bursted : " + str(score), True, white)&lt;br&gt;
    display.blit(scoreText, (150, height - lowerBound + 50))&lt;/p&gt;

&lt;p&gt;def close():&lt;br&gt;
    pygame.quit()&lt;br&gt;
    sys.exit()&lt;/p&gt;

&lt;p&gt;def game():&lt;br&gt;
    global score&lt;br&gt;
    loop = True&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while loop:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            close()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_q:
                close()
            if event.key == pygame.K_r:
                score = 0
                game()

        if event.type == pygame.MOUSEBUTTONDOWN:
            for i in range(noBalloon):
                balloons[i].burst()

    display.fill(lightBlue)

    for i in range(noBalloon):
        balloons[i].show()

    pointer()

    for i in range(noBalloon):
        balloons[i].move()


    lowerPlatform()
    showScore()
    pygame.display.update()
    clock.tick(60)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;game()&lt;/p&gt;

&lt;p&gt;Github Source Code : &lt;a href="https://github.com/arnab132/Balloon-Shooter-Game-Python"&gt;https://github.com/arnab132/Balloon-Shooter-Game-Python&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>python</category>
      <category>computerscience</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python vs Java. Key differences, Features and History</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Mon, 31 May 2021 02:01:35 +0000</pubDate>
      <link>https://dev.to/arnabdey/python-vs-java-key-differences-and-similarities-oji</link>
      <guid>https://dev.to/arnabdey/python-vs-java-key-differences-and-similarities-oji</guid>
      <description>&lt;h1&gt;
  
  
  Key Differences between Python and Java
&lt;/h1&gt;

&lt;p&gt;1.Java is a compiled+ interpreted Language whereas Python is an Interpreted Language&lt;/p&gt;

&lt;p&gt;2.Java is statically typed whereas Python is dynamically typed&lt;/p&gt;

&lt;p&gt;3.Java has a complex learning curve whereas Python is easy to learn and use&lt;/p&gt;

&lt;p&gt;4.Java is a multi-platform, object-oriented, and network-centric, programming language whereas Python is a high-level object-oriented programming language.&lt;/p&gt;

&lt;p&gt;5.Java takes 10 lines of code to read from a file while Python only needs 2 lines of code.&lt;/p&gt;

&lt;p&gt;6.Java language uses curly braces to define the beginning and end of each function and class definition, whereas Python uses indentation to separate code into separate blocks.&lt;/p&gt;

&lt;p&gt;7.In Java, multiple inheritances is partially done through interfaces, whereas Python supports both single and multiple inheritances.&lt;/p&gt;

&lt;p&gt;8.Java offers limited string related functions, whereas Python offers lots of string related functions.&lt;/p&gt;

&lt;p&gt;9.Java program can run on any computer or mobile device which is able to run the Java virtual machine (JVM) while Python programs need an interpreter installed on the target machine to translate Python code. Compared to Java, Python is less portable.&lt;/p&gt;

&lt;p&gt;10.Java is best for Desktop GUI apps, Embed Systems, Web application services, whereas Python is excellent for scientific and numeric computing, Machine learning apps, more.&lt;/p&gt;

&lt;p&gt;11.Java offers stable connectivity, while Python offers weak connectivity.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6xyz0RQq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o73a7xoq7e6p2366vico.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6xyz0RQq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o73a7xoq7e6p2366vico.png" alt="Alt Text" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Python?
&lt;/h1&gt;

&lt;p&gt;Python is a high-level object-oriented programming language. It has built-in data structures, combined with dynamic binding and typing, which makes it an ideal choice for rapid application development. Python also offers support for modules and packages, which allows system modularity and code reuse.&lt;/p&gt;

&lt;p&gt;It is one of the fastest programming languages as it requires very few lines of code. Its emphasis is on readability and simplicity, which make it a great choice for beginners.&lt;/p&gt;

&lt;h1&gt;
  
  
  Features of Python
&lt;/h1&gt;

&lt;p&gt;1.Very simple syntax compared to Java, C and C++ languages.&lt;/p&gt;

&lt;p&gt;2.Used for Machine Learning, Deep Learning, and the general overarching AI field. Very useful in data analysis and visualization.&lt;/p&gt;

&lt;p&gt;3.Extensive library and handy tools for developers&lt;/p&gt;

&lt;p&gt;4.Python is cross-compatible&lt;/p&gt;

&lt;p&gt;5.Python has its auto-installed shell&lt;/p&gt;

&lt;p&gt;6.Compared with the code of other languages, python code is easy to write and debug. Therefore, its source code is relatively easy to maintain.&lt;/p&gt;

&lt;p&gt;7.Python is a portable language so that it can run on a wide variety of Operating systems and platforms.&lt;br&gt;
Python comes with many prebuilt libraries, which makes your development task easy.&lt;/p&gt;

&lt;p&gt;8.Python helps you to make complex programming simpler. As it internally deals with memory addresses, garbage collection.&lt;/p&gt;

&lt;p&gt;9.Python provides an interactive shell that helps you to test the things before it's actual implementation.&lt;/p&gt;

&lt;p&gt;10.Python offers database interfaces to all major commercial DBMS system.&lt;/p&gt;

&lt;p&gt;11.Supports imperative and functional programming.&lt;/p&gt;

&lt;p&gt;12.Python is famous for its use in IoT.&lt;/p&gt;

&lt;h1&gt;
  
  
  Features of Java
&lt;/h1&gt;

&lt;p&gt;Here are the important features of Java.&lt;/p&gt;

&lt;p&gt;1.Write code once and run it on almost any computing platform.&lt;/p&gt;

&lt;p&gt;2.It is designed for building object-oriented applications.&lt;/p&gt;

&lt;p&gt;3.It is a multithreaded language with automatic memory management&lt;/p&gt;

&lt;p&gt;4.Facilitates distributed computing as its network-centric&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S-oVfjoX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwvjtztxcob9yr5ptich.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S-oVfjoX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwvjtztxcob9yr5ptich.png" alt="image" width="800" height="419"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h1&gt;
  
  
  History of Python
&lt;/h1&gt;

&lt;p&gt;Here, are important landmarks for Python language&lt;/p&gt;

&lt;p&gt;Python was first conceived in the late 1980s, but its implementation started only in December 1989&lt;br&gt;
It was invented in the Netherlands, by Guido van Rossum.&lt;br&gt;
Rossum published the first version of Python (0.9.0) in February 1999&lt;br&gt;
It was derived from ABC programming language, which is a general-purpose programming language.&lt;br&gt;
Nowadays, Python is maintained by a core development team although Rossum still plays a vital role in directing its progress.&lt;/p&gt;

&lt;h1&gt;
  
  
  History of Java
&lt;/h1&gt;

&lt;p&gt;Here, are important landmarks for Java language&lt;/p&gt;

&lt;p&gt;The Java language was initially called OAK. Originally, it was developed for handling portable devices and set-top boxes. Oak was a massive failure.&lt;br&gt;
In 1995, Sun changed the name to "Java" and modified the language to take advantage of the burgeoning www (World Wide Web) development business.&lt;br&gt;
Later, in 2009, Oracle Corporation acquired Sun Microsystems and took ownership of three key Sun software assets: Java, MySQL, and Solaris.&lt;/p&gt;

</description>
      <category>python</category>
      <category>java</category>
      <category>webdev</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Banker's Safety Algorithm - Python Implementation</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Mon, 31 May 2021 00:35:58 +0000</pubDate>
      <link>https://dev.to/arnabdey/banker-s-safety-algorithm-4joj</link>
      <guid>https://dev.to/arnabdey/banker-s-safety-algorithm-4joj</guid>
      <description>&lt;h1&gt;
  
  
  Implementation of Banker's Safety algorithm using Python
&lt;/h1&gt;

&lt;p&gt;The banker’s algorithm is a resource allocation and deadlock avoidance algorithm that tests for safety by simulating the allocation for predetermined maximum possible amounts of all resources, then makes an “s-state” check to test for possible activities, before deciding whether allocation should be allowed to continue.&lt;/p&gt;

&lt;p&gt;Following Data structures are used to implement the Banker’s Algorithm:&lt;/p&gt;

&lt;p&gt;Let ‘n’ be the number of processes in the system and ‘m’ be the number of resources types.&lt;/p&gt;

&lt;p&gt;Available :&lt;/p&gt;

&lt;p&gt;It is a 1-d array of size ‘m’ indicating the number of available resources of each type. Available[ j ] = k means there are ‘k’ instances of resource type Rj Max :&lt;/p&gt;

&lt;p&gt;It is a 2-d array of size ‘n*m’ that defines the maximum demand of each process in a system. Max[ i, j ] = k means process Pi may request at most ‘k’ instances of resource type Rj.&lt;/p&gt;

&lt;p&gt;Allocation :&lt;/p&gt;

&lt;p&gt;It is a 2-d array of size ‘n*m’ that defines the number of resources of each type currently allocated to each process. Allocation[ i, j ] = k means process Pi is currently allocated ‘k’ instances of resource type Rj Need :&lt;/p&gt;

&lt;p&gt;It is a 2-d array of size ‘n*m’ that indicates the remaining resource need of each process. Need [ i, j ] = k means process Pi currently allocated ‘k’ instances of resource type Rj Need [ i, j ] = Max [ i, j ] – Allocation [ i, j ] Allocationi specifies the resources currently allocated to process Pi and Needi specifies the additional resources that process Pi may still request to complete its task.&lt;/p&gt;

&lt;p&gt;Banker’s algorithm consist of Safety algorithm and Resource request algorithm&lt;/p&gt;

&lt;p&gt;Safety Algorithm&lt;/p&gt;

&lt;p&gt;The algorithm for finding out whether or not a system is in a safe state can be described as follows:&lt;/p&gt;

&lt;p&gt;Let Work and Finish be vectors of length ‘m’ and ‘n’ respectively.&lt;/p&gt;

&lt;p&gt;Initialize: Work= Available Finish [i]=false; for i=1,2,……,n&lt;/p&gt;

&lt;p&gt;Find an i such that both a) Finish [i]=false b) Need_i&amp;lt;=work&lt;/p&gt;

&lt;p&gt;if no such i exists goto step (4) Work=Work + Allocation_i Finish[i]= true goto step(2) If Finish[i]=true for all i, then the system is in safe state. Safe sequence is the sequence in which the processes can be safely executed.&lt;/p&gt;

&lt;p&gt;In this post, implementation of Safety algorithm of Banker’s Algorithm is done.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e8QPMASG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zloqtfx55zl87a9j74c4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e8QPMASG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zloqtfx55zl87a9j74c4.png" alt="image" width="598" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We must determine whether the new system state is safe. To do so, we need to execute Safety algorithm on the above given allocation chart.&lt;/p&gt;

&lt;p&gt;Following is the resource allocation graph:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--49ZXqWbi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l2mdlp359vfx5vlhts51.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--49ZXqWbi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l2mdlp359vfx5vlhts51.png" alt="image" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Executing safety algorithm shows that sequence &amp;lt; P1, P3, P4, P0, P2 &amp;gt; satisfies safety requirement.&lt;/p&gt;

&lt;p&gt;Code:&lt;/p&gt;

&lt;h1&gt;
  
  
  Python code to illustrate Banker's Algorithm
&lt;/h1&gt;

&lt;p&gt;P = 5 (Processes)&lt;br&gt;
R = 3 (Resources)&lt;/p&gt;

&lt;h1&gt;
  
  
  Function to find the need of each process
&lt;/h1&gt;

&lt;p&gt;def calculateNeed(need, maxm, allot):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Calculating Need of each P
for i in range(P):
    for j in range(R):

        # Need of instance = maxm instance -
        # allocated instance
        need[i][j] = maxm[i][j] - allot[i][j]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Function to find the system is in
&lt;/h1&gt;
&lt;h1&gt;
  
  
  safe state or not
&lt;/h1&gt;

&lt;p&gt;def isSafe(processes, avail, maxm, allot):&lt;br&gt;
    need = []&lt;br&gt;
    for i in range(P):&lt;br&gt;
        l = []&lt;br&gt;
        for j in range(R):&lt;br&gt;
            l.append(0)&lt;br&gt;
        need.append(l)&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Function to calculate need matrix
calculateNeed(need, maxm, allot)

Mark all processes as infinish
finish = [0] * P

To store safe sequence
safeSeq = [0] * P

Make a copy of available resources
work = [0] * R
for i in range(R):
    work[i] = avail[i]

While all processes are not finished or system is not in safe state.
count = 0
while (count &amp;lt; P):

    # Find a process which is not finish
    # and whose needs can be satisfied
    # with current work[] resources.
    found = False
    for p in range(P):

        # First check if a process is finished,
        # if no, go for next condition
        if (finish[p] == 0):

            # Check if for all resources
            # of current P need is less
            # than work
            for j in range(R):
                if (need[p][j] &amp;gt; work[j]):
                    break

            # If all needs of p were satisfied.
            if (j == R - 1):

                # Add the allocated resources of
                # current P to the available/work
                # resources i.e.free the resources
                for k in range(R):
                    work[k] += allot[p][k]

                # Add this process to safe sequence.
                safeSeq[count] = p
                count += 1

                # Mark this p as finished
                finish[p] = 1

                found = True

    # If we could not find a next process
    # in safe sequence.
    if (found == False):
        print("System is not in Safe state")
        return False

# If system is in safe state then
# safe sequence will be as below
print("System is in Safe state.",
        "\n Safe sequence is: ", end = " ")
print(*safeSeq)

return True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Driver code
&lt;/h1&gt;

&lt;p&gt;if &lt;strong&gt;name&lt;/strong&gt; =="&lt;strong&gt;main&lt;/strong&gt;":&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;processes = [0, 1, 2, 3, 4]

# Available instances of resources
avail = [3, 3, 2]

# Maximum R that can be allocated
# to processes
maxm = [[7, 5, 3], [3, 2, 2],
        [9, 0, 2], [2, 2, 2],
        [4, 3, 3]]

# Resources allocated to processes
allot = [[0, 1, 0], [2, 0, 0],
        [3, 0, 2], [2, 1, 1],
        [0, 0, 2]]

# Check system is in safe state or not
isSafe(processes, avail, maxm, allot)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Time complexity = O(nnm) where n = number of processes and m = number of resources.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>programming</category>
      <category>bankersalgorithm</category>
      <category>python</category>
    </item>
    <item>
      <title>Prims Algorithm using Python</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Mon, 31 May 2021 00:20:56 +0000</pubDate>
      <link>https://dev.to/arnabdey/prims-algorithm-using-python-4h15</link>
      <guid>https://dev.to/arnabdey/prims-algorithm-using-python-4h15</guid>
      <description>&lt;h1&gt;
  
  
  Prims Algorithm Graph Theory
&lt;/h1&gt;

&lt;p&gt;Prim’s algorithm is also a Greedy algorithm. It starts with an empty spanning tree. The idea is to maintain two sets of vertices. The first set contains the vertices already included in the MST, the other set contains the vertices not yet included. At every step, it considers all the edges that connect the two sets, and picks the minimum weight edge from these edges. After picking the edge, it moves the other endpoint of the edge to the set containing MST. &lt;/p&gt;

&lt;p&gt;A group of edges that connects two set of vertices in a graph is called cut in graph theory. So, at every step of Prim’s algorithm, we find a cut (of two sets, one contains the vertices already included in MST and other contains rest of the vertices), pick the minimum weight edge from the cut and include this vertex to MST Set (the set that contains already included vertices).&lt;/p&gt;

&lt;p&gt;How does Prim’s Algorithm Work? The idea behind Prim’s algorithm is simple, a spanning tree means all vertices must be connected. So the two disjoint subsets (discussed above) of vertices must be connected to make a Spanning Tree. And they must be connected with the minimum weight edge to make it a Minimum Spanning Tree.&lt;/p&gt;

&lt;p&gt;Algorithm &lt;br&gt;
1) Create a set mstSet that keeps track of vertices already included in MST. &lt;br&gt;
2) Assign a key value to all vertices in the input graph. Initialize all key values as INFINITE. Assign key value as 0 for the first vertex so that it is picked first. &lt;br&gt;
3) While mstSet doesn’t include all vertices &lt;br&gt;
….a) Pick a vertex u which is not there in mstSet and has minimum key value. &lt;br&gt;
….b) Include u to mstSet. &lt;br&gt;
….c) Update key value of all adjacent vertices of u. To update the key values, iterate through all adjacent vertices. For every adjacent vertex v, if weight of edge u-v is less than the previous key value of v, update the key value as weight of u-v&lt;/p&gt;

&lt;p&gt;The idea of using key values is to pick the minimum weight edge from cut. The key values are used only for vertices which are not yet included in MST, the key value for these vertices indicate the minimum weight edges connecting them to the set of vertices included in MST. &lt;/p&gt;

&lt;p&gt;How to implement the above algorithm? &lt;br&gt;
We use a boolean array mstSet[] to represent the set of vertices included in MST. If a value mstSet[v] is true, then vertex v is included in MST, otherwise not. Array key[] is used to store key values of all vertices. Another array parent[] to store indexes of parent nodes in MST. The parent array is the output array which is used to show the constructed MST.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ifdb6e5k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124652-0325c800-c1d3-11eb-8c4d-15ab6d5987de.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ifdb6e5k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124652-0325c800-c1d3-11eb-8c4d-15ab6d5987de.png" alt="image" width="714" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The set mstSet is initially empty and keys assigned to vertices are {0, INF, INF, INF, INF, INF, INF, INF} where INF indicates infinite. Now pick the vertex with the minimum key value. The vertex 0 is picked, include it in mstSet. So mstSet becomes {0}. After including to mstSet, update key values of adjacent vertices. Adjacent vertices of 0 are 1 and 7. The key values of 1 and 7 are updated as 4 and 8. Following subgraph shows vertices and their key values, only the vertices with finite key values are shown. The vertices included in MST are shown in green color.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rd0sbWAG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124658-091ba900-c1d3-11eb-89f4-995edbf1bc1e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rd0sbWAG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124658-091ba900-c1d3-11eb-89f4-995edbf1bc1e.png" alt="image" width="80" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pick the vertex with minimum key value and not already included in MST (not in mstSET). The vertex 1 is picked and added to mstSet. So mstSet now becomes {0, 1}. Update the key values of adjacent vertices of 1. The key value of vertex 2 becomes 8.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ARhAYK8o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124675-1b95e280-c1d3-11eb-8a7f-b52f6d4c5dd2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ARhAYK8o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124675-1b95e280-c1d3-11eb-8a7f-b52f6d4c5dd2.png" alt="image" width="150" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pick the vertex with minimum key value and not already included in MST (not in mstSET). We can either pick vertex 7 or vertex 2, let vertex 7 is picked. So mstSet now becomes {0, 1, 7}. Update the key values of adjacent vertices of 7. The key value of vertex 6 and 8 becomes finite (1 and 7 respectively). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OH-K8chW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124687-29e3fe80-c1d3-11eb-9a1a-22cb6ad19db0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OH-K8chW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124687-29e3fe80-c1d3-11eb-9a1a-22cb6ad19db0.png" alt="image" width="150" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pick the vertex with minimum key value and not already included in MST (not in mstSET). Vertex 6 is picked. So mstSet now becomes {0, 1, 7, 6}. Update the key values of adjacent vertices of 6. The key value of vertex 5 and 8 are updated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P-Fxm3RY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124699-3700ed80-c1d3-11eb-8308-fdb6ebdb9e9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P-Fxm3RY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124699-3700ed80-c1d3-11eb-8308-fdb6ebdb9e9c.png" alt="image" width="210" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We repeat the above steps until mstSet includes all vertices of given graph. Finally, we get the following graph.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RpPyAGaM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124709-42541900-c1d3-11eb-97f7-92a04c429150.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RpPyAGaM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/22562694/120124709-42541900-c1d3-11eb-97f7-92a04c429150.png" alt="image" width="260" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Python program for Prim's Minimum Spanning Tree (MST) algorithm
&lt;/h1&gt;

&lt;p&gt;The program is for adjacency matrix representation of the graph&lt;/p&gt;

&lt;p&gt;Code:&lt;/p&gt;

&lt;p&gt;import sys &lt;br&gt;
class Graph():&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def __init__(self, vertices):
    self.V = vertices
    self.graph = [[0 for column in range(vertices)]
                for row in range(vertices)]

# A utility function to print the constructed MST stored in parent[]
def printMST(self, parent):
    print "Edge \tWeight"
    for i in range(1, self.V):
        print parent[i], "-", i, "\t", self.graph[i][ parent[i] ]

# A utility function to find the vertex with
# minimum distance value, from the set of vertices
# not yet included in shortest path tree
def minKey(self, key, mstSet):

    # Initilaize min value
    min = sys.maxint

    for v in range(self.V):
        if key[v] &amp;lt; min and mstSet[v] == False:
            min = key[v]
            min_index = v

    return min_index

# Function to construct and print MST for a graph
# represented using adjacency matrix representation
def primMST(self):

    # Key values used to pick minimum weight edge in cut
    key = [sys.maxint] * self.V
    parent = [None] * self.V # Array to store constructed MST
    # Make key 0 so that this vertex is picked as first vertex
    key[0] = 0
    mstSet = [False] * self.V

    parent[0] = -1 # First node is always the root of

    for cout in range(self.V):

        # Pick the minimum distance vertex from
        # the set of vertices not yet processed.
        # u is always equal to src in first iteration
        u = self.minKey(key, mstSet)

        # Put the minimum distance vertex in
        # the shortest path tree
        mstSet[u] = True

        # Update dist value of the adjacent vertices
        # of the picked vertex only if the current
        # distance is greater than new distance and
        # the vertex in not in the shotest path tree
        for v in range(self.V):

            # graph[u][v] is non zero only for adjacent vertices of m
            # mstSet[v] is false for vertices not yet included in MST
            # Update the key only if graph[u][v] is smaller than key[v]
            if self.graph[u][v] &amp;gt; 0 and mstSet[v] == False and key[v] &amp;gt; self.graph[u][v]:
                    key[v] = self.graph[u][v]
                    parent[v] = u

    self.printMST(parent)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;g = Graph(5)&lt;br&gt;
g.graph = [ [0, 2, 0, 6, 0],&lt;br&gt;
            [2, 0, 3, 8, 5],&lt;br&gt;
            [0, 3, 0, 0, 7],&lt;br&gt;
            [6, 8, 0, 0, 9],&lt;br&gt;
            [0, 5, 7, 9, 0]]&lt;/p&gt;

&lt;p&gt;g.primMST();&lt;/p&gt;

&lt;p&gt;Time Complexity of the above program is O(V^2). If the input graph is represented using adjacency list, then the time complexity of Prim’s algorithm can be reduced to O(E log V) with the help of binary heap.&lt;/p&gt;

</description>
      <category>python</category>
      <category>primsalgorithm</category>
      <category>graphtheory</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Cyber Security: Indian View</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Tue, 05 Jan 2021 19:00:29 +0000</pubDate>
      <link>https://dev.to/arnabdey/cyber-security-indian-view-5a54</link>
      <guid>https://dev.to/arnabdey/cyber-security-indian-view-5a54</guid>
      <description>&lt;p&gt;The rapid growth of the internet and computer technology over the past few years has led to the growth in new forms of crime — dubbed cyber crime — throughout the world. The term “cyber crime” has nowhere been defined in any statute or Act passed or enacted by the Indian Parliament. Today, the world is moving towards a point where everything from banking to stock exchanges and traffic control, telephones to electric power, health care, welfare and education depends on software. This exponential growth, and the increase in the capacity and accessibility of computers coupled with the decrease in cost, has brought about revolutionary changes in every aspect of human civilization, including crime. It is rapidly evolving from simple e-mail mischief where offenders send obscene e-mail, to more serious offences like theft of information, e-mail bombing to crashing servers, etc. It is sure all of us have encountered unwanted product advertisements. Piracy is also a serious threat that involves illegal reproduction and distribution of software applications, games, movies and audio CDs which is causing a huge monetary loss to entertainment industry worldwide.&lt;/p&gt;

&lt;p&gt;Hacking is also a serious crime by a hacker who is simply a talented computer user who misuses his vast knowledge. Virus attacks that say “I love you” enter our computer and destroy all the computer information are also a serious threat. Computer frauds, thefts and harassment through social networking sites like Twitter and Facebook are also risking our lives.&lt;/p&gt;

&lt;p&gt;Undoubtedly we cannot single out only one crime that is posing maximum threat but all forms of crimes are equally posing a serious threat to both business and individuals. Cyber Crime in the Act is neither comprehensive nor exhaustive. Cases of spam, hacking, stalking and e-mail fraud are rampant although cyber crimes cells have been set-up in major Indian cities. The problem is that most cases remain unreported due to lack of awareness. Capacity of human mind is unfathomable. It is not possible to eliminate cyber crime from the cyber space. However, it is quite possible to check them.&lt;/p&gt;

&lt;p&gt;The home user segment is the largest recipient of cyber attacks as they are less likely to have established security measures in place and therefore it is necessary that people should be made aware of their rights and duties. The fight against cyber crime starts in our very own home. We should not reply any e-mail from unknown persons; learn to report spam mails to the e-mail servers. We should not upload our personal information on social networking sites or our account details on other such sites.&lt;/p&gt;

&lt;p&gt;Also the use of antivirus software can be a great help to fight against viruses and worms. Users must try and save any electronic information trail on their computers, firewalls, use of intrusion detection system, etc. and further making the application of the laws more stringent to check crime. Potentially, everything from generic word processing software to customized computer programs designed for a specific company could work on a cloud computing system.&lt;/p&gt;

&lt;p&gt;It is a good idea to rely on another computer system to run programs and store data as it would enable clients to access their applications and data from anywhere at any time. They could access the cloud computing system using any computer linked to the Internet. Data would not be confined to a hard drive on one user’s computer or even a corporation’s internal network.&lt;/p&gt;

&lt;p&gt;Also, it could bring hardware costs down as the client would not need to buy the fastest computer with the most memory, because the cloud system would take care of the rest. Often, scientists and researchers work with calculations so complex that it would take years for individual computers to complete them. The cloud system would tap into the processing power of all available computers on the back end, significantly speeding up the calculation.&lt;/p&gt;

&lt;p&gt;There will always be new and unexpected challenges to stay ahead of cyber criminals and cyber terrorists but we can win only through partnership and collaboration of both individuals and government. There is much we can do to ensure a safe, secure and trustworthy computing environment. It is crucial not only to our national sense of well-being, but also to our national security and economy.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>security</category>
      <category>discuss</category>
      <category>dohackathon</category>
    </item>
    <item>
      <title>Pygame: A Beginner's Guide</title>
      <dc:creator>Arnab Dey</dc:creator>
      <pubDate>Tue, 05 Jan 2021 18:44:36 +0000</pubDate>
      <link>https://dev.to/arnabdey/pygame-a-beginner-s-guide-5ae6</link>
      <guid>https://dev.to/arnabdey/pygame-a-beginner-s-guide-5ae6</guid>
      <description>&lt;p&gt;Pygame is a set of Python modules designed for writing video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language.&lt;/p&gt;

&lt;p&gt;Pygame is highly portable and runs on nearly every platform and operating system.&lt;/p&gt;

&lt;p&gt;Pygame itself has been downloaded millions of times.&lt;/p&gt;

&lt;p&gt;Game programming is very rewarding nowadays and it can also be used in advertising and as a teaching tool too. Game development includes mathematics, logic, physics, AI, and much more and it can be amazingly fun. In python, game programming is done in pygame and it is one of the best modules for doing so.&lt;/p&gt;

&lt;p&gt;Installing pygame: &lt;br&gt;
Pygame requires Python; if you don’t already have it, you can download it from python.org. Use python 3.6.1 or greater, because it is much friendlier to newbies, and additionally runs faster.&lt;br&gt;
The best way to install pygame is with the pip tool (which python uses to install packages). Note, this comes with python in recent versions. We use the –user flag to tell it to install into the home directory, rather than globally. &lt;/p&gt;

&lt;p&gt;python3 -m pip install -U pygame --user&lt;/p&gt;

&lt;p&gt;To see if it works, run one of the included examples: &lt;/p&gt;

&lt;p&gt;python3 -m pygame.examples.aliens&lt;/p&gt;

&lt;p&gt;If it works, we are ready to go!&lt;br&gt;
Once you have installed pygame, you’re ready to create your very first pygame instance. &lt;/p&gt;

&lt;p&gt;Pygame is free. Released under the LGPL licence, you can create open source, freeware, shareware, and commercial games with it. See the licence for full details.&lt;/p&gt;

&lt;p&gt;For a nice introduction to pygame, examine the line-by-line chimp tutorial, and the introduction for python programmers. buffer, and many other different backends... including an ASCII art backend! OpenGL is often broken on linux systems, and also on windows systems - which is why professional games use multiple backends.&lt;/p&gt;

&lt;p&gt;Code&lt;/p&gt;

&lt;h1&gt;
  
  
  import the pygame module
&lt;/h1&gt;

&lt;p&gt;import pygame&lt;/p&gt;

&lt;h1&gt;
  
  
  import pygame.locals for easier
&lt;/h1&gt;

&lt;h1&gt;
  
  
  access to key coordinates
&lt;/h1&gt;

&lt;p&gt;from pygame.locals import *&lt;/p&gt;

&lt;h1&gt;
  
  
  Define our square object and call super to
&lt;/h1&gt;

&lt;h1&gt;
  
  
  give it all the properties and methods of pygame.sprite.Sprite
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Define the class for our square objects
&lt;/h1&gt;

&lt;p&gt;class Square(pygame.sprite.Sprite):&lt;br&gt;
    def &lt;strong&gt;init&lt;/strong&gt;(self):&lt;br&gt;
        super(Square, self).&lt;strong&gt;init&lt;/strong&gt;()&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    # Define the dimension of the surface
    # Here we are making squares of side 25px
    self.surf = pygame.Surface((25, 25))

    # Define the color of the surface using RGB color coding.
    self.surf.fill((0, 200, 255))
    self.rect = self.surf.get_rect()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  initialize pygame
&lt;/h1&gt;

&lt;p&gt;pygame.init()&lt;/p&gt;
&lt;h1&gt;
  
  
  Define the dimensions of screen object
&lt;/h1&gt;

&lt;p&gt;screen = pygame.display.set_mode((800, 600))&lt;/p&gt;
&lt;h1&gt;
  
  
  instantiate all square objects
&lt;/h1&gt;

&lt;p&gt;square1 = Square()&lt;br&gt;
square2 = Square()&lt;br&gt;
square3 = Square()&lt;br&gt;
square4 = Square()&lt;/p&gt;
&lt;h1&gt;
  
  
  Variable to keep our game loop running
&lt;/h1&gt;

&lt;p&gt;gameOn = True&lt;/p&gt;
&lt;h1&gt;
  
  
  Our game loop
&lt;/h1&gt;

&lt;p&gt;while gameOn:&lt;br&gt;
    # for loop through the event queue&lt;br&gt;
    for event in pygame.event.get():&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    # Check for KEYDOWN event
    if event.type == KEYDOWN:

        # If the Backspace key has been pressed set
        # running to false to exit the main loop
        if event.key == K_BACKSPACE:
            gameOn = False

    # Check for QUIT event
    elif event.type == QUIT:
        gameOn = False

# Define where the squares will appear on the screen
# Use blit to draw them on the screen surface
screen.blit(square1.surf, (40, 40))
screen.blit(square2.surf, (40, 530))
screen.blit(square3.surf, (730, 40))
screen.blit(square4.surf, (730, 530))

# Update the display using flip
pygame.display.flip()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>pygame</category>
      <category>programming</category>
      <category>gamedev</category>
    </item>
  </channel>
</rss>
