Snake Water Gun Game In Python | Python Project for Beginners

Welcome all

Snake, water, and Gun Game is a very simple game that children usually play in a group of 2.  The project we are going to make in this tutorial is where your partner is your system and you are going to enjoy this game with your system. Did it sound interesting? If you are a beginner with python then, It is the best kickstart towards improving python programming by implementing beginner and small python projects. 


Snake-water-Gun game in Python explained and implement from scratch

This is a simple python application that will give you a knowledge of working with Python modules, especially with random. You will learn how to import any module to your application and how to use its functionalities for enabling your task to perform.

so, let's get started.

Understanding The Problem

In this project, you are player 1 and your partner is your system. you have 3 choices to play the game that is Snake, Water, and Gun. You have to take a random choice of the computer from these 3 options and you too have to choose one. 

And then we have to compare both the choices and mark the score whoever wins. The cases for winning will be as follows. 

  • Snake drinks the water (snake win)
  • Gun will sink in water (water win)
  • Gun will kill the snake (Gun win)

We will use the random module to make random choices from the computer side.

Making The Project more Interesting

Only making a simple application will not excite you so let's add some additional features to our application that attracts any user to play it multiple times. So, along with the main function like to choose between 3 options and compare them is it also possible that if the game has been played multiple times without stopping, then print the total number of times the game has played, as well as how many times the user wins and loses with several draws.

Implementation

Now, it's time to make hands dirty by implementing the proper and simple solution to the problem. Head over to your python IDE to which you are most comfortable.

Step-1) import the random module

 import random 

Step-2) Initialize all the basic parameters which we will require

  chance=0  
  wins = 0    
  lose = 0     
  draws = 0 

Step-3) Input User choice and Validate the choice.
Here, we will make use of one input prompt statement to take input. after that we will make use of a while loop to take user input and check that the is input valid or not, And if he/she wants to quit then we will break the loop.
I will be taking input in the form of char, you can also give a number and take input in integer format as well.

Code: 


Step-4) Take System Input and Compare both the inputs.
Now, it's time to take the random choices from the system compare both the inputs and mark scores and declare results.
The code will continue in a while block and this will be else blocked after upper if block.

Code:


Step-5) Display the results.

Now, the final step is to print how many times a user has played and the number of times he wins loses, and match draws. The results will print when the game ends mean the code will come out of while loop 

Code:


🔖 For the full source code visit: snake water gun game in python

CONCLUSION

That's the end of a project. Hope you enjoyed it. It is a very simple program to let you understand the basic concepts of the random module and how it is used. In our further article, we will be building projects with many advanced concepts and projects with databases and all.

This is a simple project you can place in your GitHub profile to show anyone your python repository and collection of nice codes. If you are familiar with the Python random module, then the project is very simple for you and can make within a few minutes.

Keep learning, Happy Learning 😊😊

1 Comments

If you have any doubt or suggestions then, please let me know.

Previous Post Next Post