Posts

Showing posts with the label Game Development

Python Exercise 7 --- "Snake, Water, Gun"

 Python Exercise 7 --- "Snake, Water, Gun" Today's task for you guys will be to develop your first-ever Python game i.e.,  "Snake Water Gun." (Just like --- Rock, Paper, Scissor) Most of you must already be familiar with the game. Still, I will provide you with a brief description. This is a two-player game where each player chooses one object.  As we know, there are three objects, snake, water, and gun. So, the result will be  Snake vs. Water: Snake drinks the water hence wins. Water vs. Gun: The gun will drown in water, hence a point for water Gun vs. Snake: Gun will kill the snake and win. In situations where both players choose the same object, the result will be a draw. Now moving on to instructions: You have to use a random choice function that we studied in tutorial #38, to select between, snake, water, and gun. You do not have to use a print statement in case of the above function. Then you have to give input from your side. After getting ten consecutive...

Python tutorial 32 --- "Join Function in Python"

Python tutorial 32 --- "Join Function in Python" We are all familiar with the word join and it's meaning i.e., to combine. Join has nearly the same meaning in Python, as it is used to join the elements of a list, tuple, set, etc. In this article, we will learn about the join() method and how to use it. In Python, join() is a function that is used with iterables like list, dictionaries, and string. Examples are also mentioned below so you may learn how to use join() function. If you do not know what iterables are, then check our tutorials on  Python Lists And List Functions ,  Dictionary & It's Functions and   String Slicing And Other Functions  to get the basic idea about iterables. What is the join method in Python? "Join is a function in Python, that returns a string by joining the elements of an iterable, using a string or character of our choice." In the case of join function, the iterable can be a list, dictionary, set, tuple, or even a string itsel...

Python Tutorial 31 --- "If __name__==__main__ usage & necessity"

Python Tutorial 31 --- "If __name__==__main__ usage & necessity" Using  if __name__ == “__main__”  statement is one such concept that may be difficult to grasp for beginners, but once learned, it is very helpful and used quite often afterward. However, it may seem confusing at times. This article aims to provide an understanding of the behavior of the statement and further discusses how to use it. As discussed earlier, a module is just a file containing a python code with a .py extension and can be imported to other files. That's where the keyword  __name__  comes in. Let’s understand __name__ first before moving onto if __name__ == “__main__. What is __name__? “A __name__ is a built-in variable that returns us the name of the module being used.” In simple words, by using  __name__ , we can check whether our module is being imported or run directly. If we run it in the same module that it is created in, then it will print “main” onto the screen; otherwise, i...

Python Tutorial 30 --- "How Import Works In Python?"

Python Tutorial 30 --- "How Import Works In Python?" As always I am again going to repeat: not to name our file similar to a module name. The reason for that, I finally will be sharing with you in this particular tutorial.We are going to name our files file1.py and file2.py. In this tutorial we aim to understand the working of the import statement, so we can have a better grasp of the concept and resolve common importing issues. In Python, we give access to a module by using a keyword  import . To use any package in our code, we must make it accessible by importing it first. There are many ways we can import a module in python, but what can be easier than using a single keyword, so it is also the most common way for importing. How does the import keyword work? When we write a certain module name along with the  import  keyword, it will start searching for a file with that name having an extension  .py . After finding the file, it will import it into our program, whic...

Python Tutorial 28 --- "Virtual Environment & Requirements.txt"

Image
Python Tutorial 28 --- "Virtual Environment & Requirements.txt" So, guys in this tutorial our introduction will be a little different than usual as we are not going to using Pycharm. Instead today we are going to work with PowerShell. It may be a little unusual but don't worry, as I am here to guide you through every step. So, let's get started. First, we will create a new folder. After opening the folder we will now open our PowerShell window using shift + mouse right-click. Our PowerShell window will appear like this: Note that the path it is showing is of our current folder. That is actually the benefit of using shift + mouse right-click. Now let us move on to some theoretical concept. A virtual environment is a tool or an aid provided to us by Python to keep the dependencies that we have utilized earlier in a few projects, constant. In simple terms, after some duration, Python keeps on launching and upgrading its versions. The new versions yet being better can...