This page contains examples of basic concepts of Python programming; List Programs; String Programs; Dictionary Programs. Tuple Programs; Searching and Sorting Programs; Pattern Printing; Date-Time Programs; More Python ...
About Me
Get link
Facebook
X
Pinterest
Email
Other Apps
I write daily BLOGS about PYTHON with "Source Code"
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 29 --- "Enumerate Function" “ An enumerate is a built-in function that provides an index to data structure elements, making iterations through them easier and simpler.” In previous tutorials we have seen many methods that print items of different data structures onto the screen. For these kinds of operations, we need to have a for loop along with an iterator and an integer variable in which we have to increment every time the loop runs. Well, python provides us with a simple and easy solution to deal with certain situations by providing us with a built-in function known as “ enumerate function .” Using the enumerate function, we can summarize the code and make it easier and simpler to use. It is really important to know the concept of Enumerate function so that you can apply this concept to your code. Let us understand the working of enumerate function: What enumerate function does is, it assigns an index to every element or value in th...
Python Tutorial 3--- "Variables, Datatypes and Typecasting " This PROGRAM or TUTORIAL about Python's "Variables, Datatypes and Typecasting " DOC Variable: A variable is a name given to any storage area or memory location in a program. In simple words, we can say that a variable is a container that contains some information, and whenever we need that information, we use the name of that container to access it. Let's create a variable: a = 34 # Variable storing an integer b = 23.2 # Variable storing real number Here a and b are variables, and we can use a to access 34 and b to access 23.2. We can also overwrite the values in a and b Data Types in Python: Primarily there are following data types in Python. Integers (<class 'int'>): Used to store integers Floating point numbers (<class 'float'>): Used to store decimal or floating-point numbers Strings (<class 'str'>): Used to store st...
Comments
Post a Comment