Posts

EXERCISE :6 SNAKE, WATER, GUN

  """ Exercise 6: Game Development: Snake Water Gun Today's task for you guys will be to develop your first-ever Python game i.e., "Snake Water Gun." 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 inputs, the computer wil...

Map, Filter & Reduce

Image
  Python provides many built-in functions that are predefined and can be used by the programmers by just calling them. These functions not only ease our work but also create a standard coding environment. In this tutorial, we will learn about three important functions:  map(), filter,  and  reduce()  in Python. These functions are most commonly used with Lambda function.  "Lambda functions are functions that do have any name" . These functions are used as parameters to other functions. If you do not know what lambda functions are, then I recommend you to check  Anonymous/Lambda Functions In Python    tutorial first to avoid any confusion.   Figure 1:Anonymous/Lambda Functions In Python Why are lambdas relevant to map(), filter() and reduce()? These three methods expect a function object as the first argument. This function object can be a normal or predefined function. Most of the time, functions passed to map(), filter(), and reduce() a...

Join Function In Python

  We are going to name our file   JOINFUNC.py   here.  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...