Skip to main content

Posts

Showing posts from July, 2022

How to Code a Number Guess Game With Python.

How to Code an Advanced Number Guess Game with Python. banner of the game by me:) Hello everyone, I am sure you have played the Number Wordle (Number Guess) Game. Have you ever wanted to create your own number guess game? If yes, this is the time.  It is a game like a wordle to friends who don't know what a number guess game is. The Computer generates a random number; all you have to do is guess that number. If your guess is correct you are rewarded with some points and granted access to higher levels. With Python, you can code this very easily, and let's get started. At this level, we will create a CLI game so that you can understand the basics, and let's move to GUI when you are ready. Prerequisites. All you need is Python and if you have not installed Python yet, visit  https://www.python.org/downloads/ and download the appropriate Python version for you. Getting Started. Create an ASCII banner. First, we want a banner to show the user when they enter the game. It will

Create a URL Shortener app with Python and Django. Part-2

Create a URL Shortener app with Python and Django. Part-2 READ PART 1 :  https://blogofchamodh.blogspot.com/2022/07/create-url-shortener-app-with-python.html READ PART 3:  https://blogofchamodh.blogspot.com/2022/08/create-url-shortener-app-with-python.html Photo by  LinkedIn Sales Solutions  on  Unsplash To start the project you have to use the Django-admin  command. This tutorial series is to teach how to create a URL Shortener app and I don't explain the very basics. Please let me know if you want a primary tutorial series in the comment section below. 1. Starting the project. 2. Starting the app To start a Django app we run the python manage.py [APP_NAME]    command. 2. Register the app To tell Django to consider url_shortener as an app for our project we have to edit the settings.py file inside the Shortener Folder. Add a line in the following format to the INSTALLED_APPS list.   [APP_NAME].apps.[APP_CONFIG_NAME]   To find the [ APP_CONFIG_NAME], open the apps.py f

How to find the resultant of multiple vectors with Python.

Hello everyone, welcome back to my blog. Two years ago, I published a post on "How to find the resultant of two vectors with Python." and it has become the most popular post on my blog. So I thought to give a deep explanation of the updated version of that resultant finder. In the "How to find the Resultant of two vectors" script we learned, how to write a script that finds the resultant of just two vectors but what if we want to find the resultant of three or more vectors? We have to write a new script. Logic. Here we use different logic to calculate the resultant. First, we collect all the vectors with the angle they make with the horizontal level to calculate their x and y components. Look at the image below. I hope that will help you to get an idea of what x and y components are and how to calculate them. Then we calculate the sum of all x components and y components. As the direction of all components of each category (x & y), we can simply add them to

Create a URL Shortener app with Python and Django Easily. Part-1

Create a URL Shortener app with Django  Part 1. How to set up and activate the virtual environment & installing Django. READ PART 2:   https://blogofchamodh.blogspot.com/2022/07/create-url-shortener-app-with-python-part2.html READ PART 3:  https://blogofchamodh.blogspot.com/2022/08/create-url-shortener-app-with-python.html As promised in the previous post ( How to generate a random string with Python. ), I am starting a post series on creating a URL Shortener app with Django and Python. Photo by LinkedIn Sales Solutions on Unsplash Getting Started INFO: I am using GitBash CLI and if anyone uses it please download and install it following the link below.  https://gitforwindows.org/ First, we have to create a virtual environment so that we can isolate our project. Even if there are too many ways to do it,  I am going to use virtualenv to do it. To create a virtual environment, follow the instructions below. 1. Create a new folder. To make things easier, we are going to create a ne

How to generate a random string with Python.

Photo by Pixabay. Hello everyone, welcome back to my blog. Today I will talk about how to generate a random string with Python. As a developer developing random strings is a vital task. I am working on a simple URL shortener app with Django. I will bring another article on that project as well. Before getting started, don't forget to subscribe to my blog using the subscribe button in the top-right corner. Importing modules. To get our job done, we have to import two important modules. They are built-in and no need to use PIP to install. random module. string module. here we use the random module to choose some random characters which are provided by the string module. you can use the following piece of code to import them. import random import string Writing the function To generate the random string we can create a function that returns the random string whenever we call. def create_string ( size = 10 , chars = string . ascii_lowercase + string . digits ):     return "

Flip a coin million times w/ Python

Photo by ZSun Fu on Unsplash Welcome everyone to my blog. I could not write a new blog post for the last year because of my heavy work schedule. So I thought to write an article on a recent project done by me. Let's get started. Imagine that you want to flip a coin. Perhaps you don't need a complex python script to flip and find a result but what if you're going to flip a coin 2 million times and check the results. Then you have to invite Python to do all the hard work for you. If you are not interested to dive deep, just go ahead and check my project on Github. And also don't forget to follow my profile for the latest fun projects. and if you are a Python expert please feel free to fork.  🍴🍴 Link: https://github.com/chamodhk/coin-flipper Import the libraries you want! If you aren't using a GUI all you have to import is the random module. If you are an expert you don't have to import it too because you can write a function to get the random part done. im