Learn Python by Building 25+ Projects (With Source Code)

Looking for the best way to learn Python? Build projects! This article provides a list of 25+ Python projects for beginners to advanced coders, with source code provided for all projects. In this article, we are going to cover Python Project Ideas for beginners and experts with valid source codes.

Whether you're just starting out with Python or you're looking to improve your skills, there's a project on this list for you. From simple command-line tools to complex web applications, there's a project for everyone.

Best Python Books: https://bit.ly/3REqgBm

Top 10 Python Projects for Beginners

Well, if you’ve just started out learning Python or are at a stage where you really want to get your hands dirty, then follow this section. We have discussed a few Python projects with source codes here for you to delve deep and get expertise:

1. Email Slicer

One of the easiest projects to start with is an Email Slicer. The first question that comes to our mind is: what is an email slicer?

In essence, Email Slicer is just a simple tool that will take an email address as input and slice it to produce the username and the domain associated with it. The email must be divided into two strings by using ‘@’ as the separator.

For example

One of the easiest projects to start with is an Email Slicer. The first question that comes to our mind is: what is an email slicer?

In essence, Email Slicer is just a simple tool that will take an email address as input and slice it to produce the username and the domain associated with it. The email must be divided into two strings by using ‘@’ as the separator.

For example

Input:

codequs@gmail.com

 Output:

Your username is InterviewBit & domain is gmail.com

Here we got codequs as the username and gmail.com as a domain.

Let’s get right to coding and build this quick and easy project. It doesn’t require any setup, so let’s get started!

You can check Source Code

2. Number to Words

This Python project can make you spell out the numbers you may define. This Python code will help you support more than a million inputs along with non-positive integers like zero, negative integers, or floating numbers. 

You can check the Source Code

3. Google Image downloader

Need a bunch of images for your new project? Then just run this program and download any number of images for a  topic. Only ensure that you do not violate copyright issues and give due credit to the owner if needed. 

You can check the Source Code

4. Contact List

As old school as it may sound, creating a contact list, adding contacts along with phone numbers or emails, and editing them, are still prevalent. To create one, you can use the SQLAlchemy library which uses SQLite to store contacts. Your contact book application should be organized into modules and packages, and you should give it a coherent structure.

In order to get the most out of this project, some previous experience with Python and PyQt programming would be helpful. As a result, you will need to know the following:

  • Develop GUI applications with PyQt and Python
  • Develop GUI applications with PyQt and Python
  • Use Python and PyQt to manage SQL databases
  • Working with SQLite databases

So, In this project, you’ll learn how to:

  • Implement a GUI for your contact book application with Python and PyQt
  • Using PyQt’s SQL support to connect the application to an SQLite database 
  •  Using PyQt’s Model-View architecture for managing contact data

By the end of this project, you’ll have an application that allows you to manage and store your contacts.

You can check the Source Code:

5. Monty Hall Simulation Problem

Monty hall’s problem comes from a famous movie where three doors are used to help you win a car. How? Each door hides something behind it–a car and two goats. Any door can have the car while the remaining two have goats. The probability to find a car is ⅓. Now, if you select Door 1 and the host opens Door 3 to find a goat, your chances just become ⅔. This program will help you solve this problem. 

Work Flow and Logic 

The following are the main points of the simulation:

  • As there are three doors, a random permutation of the numbers 1, 2, and 3 would be generated, with each number representing a door. This permutation contains the first two numbers that correspond to the location of goats behind the door, and the third number corresponds to a car behind the door.
  • Using images, the configuration is represented graphically. Every configuration has its own image.
  • Only the door behind which there is a goat is to be revealed after the user has chosen a door number according to the puzzle. By selecting the door behind which the car is parked, the user can then reveal either of the other two doors. If the user selects a door behind which there is a goat, only one of the two remaining doors can be revealed (since the previously selected door cannot be revealed).

You can check the Source Code:

6. Image to Sound

You can create sound from image files now. Imagine displaying an image from the forest with the actual forest sound in the background–Just adds to the drama. For this to run, have an image file and sound file (in .mp3 format) ready.

In this tutorial, we will learn how to use Optical Character Recognition (OCR) and Speech Synthesis, and then combine them into a single working program.

With one line of code, we can perform optical character recognition using the Python Library pytesseract.

Converting Generated Text to speech
In Python, you can convert speech to text in a variety of ways.
We will use Google Text to Speech to convert our decoded text into audio in this project.

gTTS(Google Text to Speech)
As the following example shows, doing text-to-speech with one line of code is very simple.

>>> from gtts import gTTS
>>> gTTS('Welcome To codequs').save('codequs.mp3')

You can check the Source Code:

7. Snake Game

With older Nokia phones, we had an old-age addiction with the snake game. But of course, we don’t have it anymore. What if you could write one for yourself using Python? Beginner Python programmers who are interested in making something easier in their domain can definitely try this out, and the module Turtle was built specifically for beginners to try and submit as part of the project. The project will be done in Python 3.

As a result, we will create a Python-based game using the following modules:

  • Turtle: It’s a pre-installed Python library that lets users create shapes and pictures using a virtual canvas.
  • Time: Use this function to count how many seconds have passed since the epoch.

Random: This function generates random numbers in Python by using the random module.

You can check the Source Code:

8. GIF Creator

A GIF is an animated series of images that conveys an impression of movement. Would you like to create your own? Sure! Here is a Python project for creating GIFs. 

Let’s get started.

As famous as the gif market has become over these years now, demand for quality gifs is going up. The majority of people use these to communicate with others on social media platforms like WhatsApp, Instagram, etc. We will build a GIF Creator that creates GIFs from images here.

In this project, we will be using the MoviePy python module for development purposes. 

What is MoviePy?

MoviePy is a Python module that can be used to edit video (for example, to make cuts, concatenations, and title insertions), to do video compositing (also known as non-linear editing), or to do video processing. It is capable of reading and writing the most common video formats, including GIFs.

For installing MoviePy we can run the following command in our terminal:

pip install moviepy

You can check the Source Code:

9. Website Blocker

Aren’t we all tired of random pop-ups during site surfing? So, we can create website blockers for restraining pushy ads by creating this Python project. A website blocker prevents access to websites permanently or on a schedule. We can block all websites from unwanted categories so that we can use the internet safely.

So, the Website Blocker Python project’s goal is to block websites from any device. By blocking websites from the user’s device, this project will help them stay away from distractions as they will not be able to open them.

This project enables the user to enter multiple websites to block, and then clicking on the block button will check whether the website has already been blocked, otherwise, block all those websites and print ‘blocked’.

Remember, when you code this, you can add the sites you need to block by editing sites_to_block, changing the host, or editing the time when you need to block the sites.

How do we do it?

A host file is part of every operating system. Operating systems may have different locations for the host file. It maps the hostname to the IP address of the machine. Here, we list the websites we want to block.

You can check the Source Code:

10. Binary Search Algorithm

As the binary term explains, the system will take any input starting from 0 to any range that you specify and display a range of numbers with a difference of two.

11. Dice Rolling Simulator

We will be imitating a rolling dice as the program’s title suggests. This is one of the interesting python projects that generate a random number each time the program runs. The user can use the dice as often as he wants. The program will generate a random number between 1 and 6 when the user rolls the dice.

The user will then see the number. Additionally, the application asks users whether they would like to roll the dice again. Additionally, the program should be able to randomly pick a number between 1 and 6 and print it. 

Using a text-based user interface (TUI), you will be able to specify the number of six-sided dice you would like to roll with your dice-rolling simulator app.

Since we randomize the dice simulator outputs here, we’ll use the random module.

So, in this project, you will learn :

  • Simulating the rolling of dice by using random.randint()
  • Using methods such as .center() and .join() to manipulate strings
  • Using the built-in input() function to take the user’s input at the command line
  • how to parse and validate the user’s input

You can check Source Code

Top 12 Python Project Ideas for Intermediate

If you have little expertise with Python projects, you can directly start building these projects. These projects are for intermediate users who have some knowledge and wish to create more.

1. Image to Story

Want to create amazing stories from images? This project will let you produce a sentence after capturing the image. For this to work, download some pre-trained models and style vectors. Run:

wget http://www.cs.toronto.edu/~rkiros/neural_storyteller.zip

Finally, we need the VGG-19 ConvNet parameters. You can obtain them by running:

wget 
https://s3.amazonaws.com/lasagne/recipes/pretrained/imagenet/vgg19.pkl

Open config.py and specify the locations of all of the models and style vectors that you downloaded.
For running on CPU, you will need to download the VGG-19 prototxt and model by:

wget 
http://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_19_layers.caffemodel
wget 
https://gist.githubusercontent.com/ksimonyan/3785162f95cd2d5fee77/raw/bb2b4fe0a9bb0669211cf3d0bc949dfdda173e9e/VGG_ILSVRC_19_layers_deploy.prototxt

Now, to generate a story, open Ipython and run:

import generate
z = generate.load_all()
generate.story(z, './images/ex1.jpg')

2. Number Guessing

A fun project to guess the number after getting a few hints from the computer. Every time a user gives a wrong answer, another hint pops up to make it easier for them.

What you will be doing in this project:

  • You can build a game where the user selects a range of numbers to guess.
  • Assume User selected a range, i.e., from A to B, where A and B belong to Integer.
  • The user has to guess an integer selected by the system within the minimum number of guesses

Here are the steps for building the project:

  • The user enters the lower and upper bounds of the range.
  • As a result, the compiler generates a random integer between the range and stores it in a variable for future use.
  • A while loop will be created for repetitive guessing.
  • When a user guesses a number that is greater than a randomly selected number, the user receives the message “Try Again!”. Your guess was too high.
  • If the user guesses a number smaller than a randomly selected number, the user gets an output of “Try Again!”.Your guess was too small”
  • In addition, if the user guesses within a minimum number of attempts, they get a “Congratulations!” message.
  • If the user fails to guess the integer in the minimum number of guesses, he/she will receive a “Better Luck Next Time!

You can check the Source Code:

3. Fibonacci Generator

In your coding journey, you must have come across the Fibonacci series which is a sequence of numbers in which each number is the sum of its two preceding numbers. 

A Fibonacci number sequence is defined mathematically by its recurrence relationship

Fn = Fn-1 + Fn-2

Where F0=0 and F1=1

As the name suggests, in this project we will be creating a recursive function that takes input and checks whether the number belongs to the Fibonacci sequence or not.

Things to remember:

  • Ensure your data type is large enough to accommodate Fibonacci values
  • Make sure you use memoization by storing every value calculated at runtime when you use the top-down approach to recursion

You can check the Source Code

4. Voice Assistant

Looking at the market majorly, we realise voice assistants are all up to take over our tasks. Siri, Alexa, and OkGoogle are already leading the market. How about you have a personal assistant of your own.

Python is, as we all know, an excellent language for scriptwriters and developers. Let’s create a script for Voice Assistant using Python. The assistant can be manipulated according to the user’s needs. 

Modules needed for this project:

Subprocesses:-Module for getting details of system subprocesses that are used by various commands such as shutdown, sleep, etc. Python includes this module by default. 

WolframAlpha:- Based on Wolfram’s algorithms, knowledgebase, and AI technology, WolframAlpha is used to compute expert-level answers. 

Pyttsx3:- This module converts text to speech in a program and works offline. 

Tkinter:- This module is used for building GUI and comes inbuilt with Python.  

Wikipedia:– As we all know Wikipedia is a great source of knowledge just like IntervewBit. We use the Wikipedia module to access information from Wikipedia or to search Wikipedia. 

Speech Recognition:- In building an application for voice assistant, one of the most important things is that the assistant recognizes your voice (meaning what you want to ask). 

Web browser:- This built-in module is used for web search.

Ecapture:- This module is used for capturing images from your camera.

Pyjokes:- Pyjokes is a tool for collecting Python jokes online. 

Datetime:- Shows date and time

Twilio:- Twilio is used for making calls and sending messages.

Requests: Requests are used to make GET and POST requests. 

BeautifulSoup: The Beautiful Soup library allows you to easily scrape information from web pages.

You can check the Source Code:

5. Password Generator

The most difficult part of managing multiple accounts is generating a different strong password for each. A strong password is a mix of alphabets, numbers, and alphanumeric characters. Therefore, the best use of Python could be building a project where you could generate random passwords for any of your accounts.

In order to create a strong password, users can use this password generator to generate a random and customized password.

Steps required for building this project:

  • All characters should be stored as a list. This can be done with the string module of Python or by typing each character individually.
  • Ask the user for the length of the password.
  • Use random.shuffle to shuffle the characters.
  • Create an empty list to store the password.
  • Iterate length times to generate the password.
  • Choose a random character from all the characters using the random.choice method.
  • Add the random character to the password.
  • Randomize the resultant list of passwords.
  • Use the join method to create a string from the list of passwords.
  • Print the password.

You can check the Source Code:

6. Reddit Bot

We all have used Reddit for one purpose or the other. The famous question-answer app can now also have a bot linked to it. The bot will automate comments on the posts based on specified criteria.

For this to work:

  • Pick a subreddit to scan
  • Designate a specific comment to search for
  • Set your bot’s reply
  • Create a config.py file with your Reddit account details and Reddit.py file with the bot requirements
  • Pre-requisites: Python, Praw, and A reddit account

Config.py

username = "RedditUsername"
password = "password"
client_id = "idGoesHere"
client_secret = "secretGoesHere"

Reddit.py

import praw
import config
import time
import os

def bot_login():
    print "Logging in..."
    r = praw.Reddit(username = config.username,
                password = config.password,
                client_id = config.client_id,
                client_secret = config.client_secret,
                user_agent = "The Reddit Commenter v1.0")
    print "Logged in!"

    return r

def run_bot(r, comments_replied_to):
    print "Searching last 1,000 comments"

    for comment in r.subreddit('test').comments(limit=1000):
        if "sample user comment" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
            print "String with \"sample user comment\" found in comment " + comment.id
            comment.reply("Hey, I like your comment!")
            print "Replied to comment " + comment.id

            comments_replied_to.append(comment.id)

            with open ("comments_replied_to.txt", "a") as f:
                f.write(comment.id + "\n")

    print "Search Completed."

    print comments_replied_to

    print "Sleeping for 10 seconds..."
    #Sleep for 10 seconds...		
    time.sleep(10)

def get_saved_comments():

if not os.path.isfile("comments_replied_to.txt"):
        comments_replied_to = []
    else:
        with open("comments_replied_to.txt", "r") as f:
            comments_replied_to = f.read()
            comments_replied_to = comments_replied_to.split("\n")
            comments_replied_to = filter(None, comments_replied_to)

    return comments_replied_to

r = bot_login()
comments_replied_to = get_saved_comments()
print comments_replied_to

while True:
    run_bot(r, comments_replied_to)

You can check the Source Code

7. Black Jack

Creating the most famous card game of the casinos in Python would be a wonderful project. This game is played with a deck of 52 cards where the strategies play at best. Shuffle the cards, announce the buy-in amount, and decide the ranking of the cards. For ex. If Ace is given number 1 or 11. The player who gets the value of cards to 21 wins the game.

In case you need a quick refresher, here is how it works:

  • Bets are placed by players.
  • Players are dealt with 2 cards.
  • The dealer is dealt 2 cards, with the second one hidden from the players.
  • If you beat the dealer in this way, you win from the casino what you bet (you also win if the dealer busts). The goal is to have a higher point total than the dealer (but not more than 21). Each other card has a face value (face cards have a value of 10), except that aces have a value of either 1 or 11.
  • Blackjack refers to an initial 2 card hand composed of an ace and a face card. It is the best possible hand.
  • Immediately after the first round of dealing, each player has the option of hitting (receiving more cards) or staying (not receiving any more cards). The player loses his or her bet if hitting results in busting (going over 21).
  • After all the players have hit and stayed, the dealer flips over his hidden card. If the dealer’s total is less than 17, then he or she must hit (receive a new card). It repeats until either the dealer’s hand totals 17 or more, or the dealer busts (goes over 21).
  • After the dealer is done, the final results are decided – if the dealer busts, then any players who did not bust earlier will win their bet. As long as the dealer does not bust, each player’s total is compared to the dealer’s. If the player’s total exceeds the dealer’s, he or she wins money (in the amount of the bet). Any player whose total is less than the dealer’s loses. In the event of a tie, no money is exchanged.

You can check the Source Code

8. Recursive Triangle

This program creates a triangle using stars, recursively.

def triangle(n):
    return recursive_triangle(n, n)

def recursive_triangle(x, n):
    # First we must verify that both input values are integers.
    if type(x) != int or type(n) != int:
        return 'error'
    # If x is bigger than n, we will still only print the full triangle, so we can set them equal.
    if x > n:
        x = n
    # If either value is zero, the output should be an empty string because there are no lines or triangle to print.
    if x == 0 or n == 0:
        return ''
    # Let's set some variable names to help us out.
    star_print = n
    line_number = x
    # I'll create an empty string that we can concatenate values to.
    line_print = ''

# The difference value will determine how many shapes are needed to fill the line before the stars are printed.
    difference = star_print - line_number
    # If difference is not zero, we will print that value of spaces before the stars. The star print will be the
    # remainder, also known as line number.
    if difference != 0:
        line_print += ' '*difference
        line_print += '*'*line_number
    # If difference is zero, then we can just fill the line with stars.
    else:
        line_print += '*'*star_print
    # If the line number is greater than one, we can return our string and use the recursive call to run the function
    # again with the line number as one value less.
    if line_number > 1:
        return line_print+'\n'+str(recursive_triangle(line_number-1, star_print))
    # If the line number is exactly one, then we don't need to use the recursive call.
    elif line_number == 1:
        return line_print

9. Queue

Implements queue data structure. A queue is an entity that maintains the data in a linear format and processes it in FIFO order.

10. Rock Paper Scissors Game

In this project, you will be going to program a very fun python game. The goal of the rock-paper-scissor python project is to create a game that can be played from any computer, anywhere, and at any time.It is possible to indicate the move with a single alphabet or by entering an entire string

We will use the Tkinter and random module of Python to implement this python rock paper scissors game.

  • Tkinter is a standard GUI library that creates GUI apps easily.
  • The random module is used to generate random numbers.

Functions Used:

This program requires a number of functions, so let’s take a look at them all:

  • A Random function will be created for generating rock, paper, or scissors. 
  • A valid function will be created to check the validity of the move performed by the user.
  • A result function will be created to declare the winner of each round.
  • A scorekeeper to keep a track of the score in each round.

You can check the Source Code.

11. Currency Converter

Python can be used to develop this simple GUI application. This project is about building a currency converter that will allow you to convert currencies from one unit to another, such as converting Indian rupee into pounds or euros.

The design of this application will be straightforward, focusing on the primary function, which is converting currency units. With Tkinter, you can access the Tk GUI toolkit, which comes with Python.

This currency converter project in python requires a basic understanding of python programming and the pygame library.

Tkinter – For UI
requests – to get the URL

In your terminal, type the following code to install the Tkinter and requests libraries:

pip install tkinterpip install requests

Here are the steps required for building the Python Project on Currency Converter:

  • Real-time Exchange rates: We will use: https://api.exchangerate-api.com/v4/latest/USD to get real-time exchange rates
  • Import required Libraries: Our Python project uses the Tkinter and requests libraries. We must import the libraries.
  • CurrencyConverter Class:Afterward, we will create a CurrencyConverter class that gathers real-time exchange rates, converts the currency, and returns the converted amount.
  • UI for CurrencyConverter: Next step will be to create a user interface for a currency converter.
  • Lastly create the main function.

    You can check Source Code

12. Quiz Application

There are many things to learn in the world, and quizzes help in testing the understanding of those concepts. The Quiz Application will present questions to users and expect the users to respond accordingly. Think of it as a questionnaire.

Using the Quiz Application, it will be possible for special users, called administrators, to create tests, and then regular users can answer the questions and test their understanding.

  • This project consists of setting quizzes and asking people to answer them. Therefore, users should be able to ask questions, and other users should be able to answer them. The application will then display the final score and the correct answers.
  • Users should be able to create tests by uploading a text file with the questions and answers. You will be able to choose the format of the text file, so the application can convert the file into a quiz.
  • For this project, you will need to implement a database. Users’ questions, possible answers, correct answers, and scores will be stored in a database.

You can check the Source Code

Top 5 Python Project Ideas for Advanced Users

These Python projects are for all those developers who wish to explode the market with high-end applications for use.

1. Content Aggregator

Using Python and the popular Django framework, you’ll build a content aggregator from scratch.

Surfing through various websites to collate the best material for content is a tedious task. With this Python Project, searching and collating all the resources and materials in one place becomes a lot easier.

In this Project, you’ll learn:

  • RSS feeds: how to use them
  • How to create custom Django management commands
  • How to run your custom command when you specify a schedule
  • Testing your Django app’s functionality with unit tests

The major steps involved in this project are:

  • Create a list of sites from which you want to collect data.
  • Scrape these sites’ content using libraries like HTTP request sender and BeautifulSoup.
  • Apscheduler is used for background content management.
  • Scrapped content is stored in a database.

You can check the Source Code:

2. Building Chatbot

A chatbot is a software application based on artificial intelligence that interacts with humans in their own natural language.

Every site that we open nowadays has a chatbot integrated to extract information from the user/visitor in real-time. This way the problem of manually looking out for customers is solved. Now, you can even create chatbots that talk to the user and grab information. This AI provides numerous features like learning, memory, conditional switch, topic-based conversation handling, etc.

For building a chatbot,

You must import all the necessary packages and initialize the variables. If you work with text data, remember to perform data preprocessing on your dataset before designing an ML model.

In this situation, tokenizing helps to fragment large text datasets into small, readable chunks (like words). Afterwards, you can also lemmatize a word, which transforms it into its lemma form. Afterwards, it creates a pickle file to store the Python objects used to predict the bot’s responses. 

A crucial part of the chatbot development process is creating the training and testing datasets. 

You can check the Source Code:

3. Face Mask Detection

With the current pandemic times, a face mask is highly appreciated wherever we go. But it also becomes tiresome to manually detect people without a mask. This Python Project lets you detect a mask and prompt any error. This can be applied in malls or any public meeting place. 

What we will be doing in this project:

  •  Using Python, Keras, and OpenCV, we will develop a deep-learning model for face mask detection. 
  • We will develop a face mask detector model to detect whether a person is wearing a mask or not. 
  • Keras-based network architecture is used to train the model. 
  • First, the model is trained, and then the OpenCV program is used to test the model using a webcam.

Introduction to Image Processing

We need to understand how to handle images before implementing the face mask detection problem. An image is simply a collection of colors in red, green, and blue. As humans, we see images with objects and shapes in them, but a computer sees them as color arrays with values ranging from 0 to 255.

Computers perceive images differently from humans. But that’s the good news for us because if we get an array of the image, then it becomes a lot easier to implement any algorithm on the array.

Steps to Perform Image Processing :

  • Use Python or any other programming language you are using to load images.
  • Convert the images into an array.
  • And finally, apply some algorithms.

It is also good that we have a library called OpenCV that will allow us to read the image and return an array of colour pixels.

For the source code, you can refer to the Github link.

4. Plagiarism Checker

A nightmare for a writer is whether or not the written work falls into plagiarism barriers. The plagiarism tool scans through your work to find an overlap from an existing source posted online. 

To avoid any overlap for stealing someone’s work, we tend to put our work through plagiarism checkers. But the tools cost a fortune. So, with this Python project, you can create a plagiarism checker to scour through any writing work. This Python project uses a Natural Language Processing tool along with a search API to prepare a full-fledged usable Plagiarism checker. 

What you will need:

  • TensorFlow is an extremely powerful library for building neural networks with a variety of parameters. A neural network consists of an input layer, hidden layers, and an output layer.
  • We will also need Natural Language Toolkit (NLTK) to prepare the dataset with our own texts for training the machine learning model. We must tokenize the root words from texts in order to train the machine learning model. 

Input will be a CSV file with only one ‘Text’ column. The file is named InterviewBit.csv. The text in each row of the column ‘Text’ will be different. You can make these texts as long as you want, as long as they do not contain commas or special symbols. For longer texts, the model will require more epochs to provide higher accuracy.  

You will be learning the following things while building this project:

  • the basic knowledge of neural networks
  •  stemming words
  •  Tokenization
  •  natural language processing

You can check the Source Code:

5. Music Player

Almost everyone loves to listen to music. Imagine, creating a music player of your own that involves scanning through project files to find music files, browsing through various tracks, adding music from your favourite artists, or controlling the volume. 

With this Python project, you create a full-fledged music player with an interactive UI to play around with.

To be able to build this project you should have Tkinter and pygame installed on your device.

  1. We will use Tkinter to render our application’s menu and its buttons, as well as to load the music from files, and then to play, pause, and stop it using pygame library. Also, Tkinter is a lightweight module and can be used to create cross-platform applications (the same code will work on Windows, macOS, and Linux).
     
  2. In Python, Pygame provides an inbuilt method called mixer () which allows us to deal with sound files easily, i.e:
  •   loading and playing music
  •    pausing and unpausing music
  •    stopping the music file

Functions Used

  • playsong: The active song is loaded from the list and played. When the user clicks “play”, the song is played.
  • pausesong: If the user clicks “pausesong”, the song is paused. It is executed when the user clicks “pause”.
  • stopsong: It stops the song. After clicking “stop”, it is executed.
  • resumesong: It is used for resuming the required song. When the user clicks “resume” it is executed.

You can check the Source Code:

Source: https://www.interviewbit.com 

#python #programming #developer #morioh #programmer #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming #pythonquiz #ai #ml #machinelearning #datascience

Learn Python by Building 25+ Projects (With Source Code)
2 Likes19.95 GEEK