Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

snake water gun game in python

import random

# Snake Water Gun or Rock Paper Scissors
def gameWin(comp, you):
    # If two values are equal, declare a tie!
    if comp == you:     
        return None

    # Check for all possibilities when computer chose s
    elif comp == 's':
        if you=='w':
            return False
        elif you=='g':
            return True
    
    # Check for all possibilities when computer chose w
    elif comp == 'w':
        if you=='g':
            return False
        elif you=='s':
            return True
    
    # Check for all possibilities when computer chose g
    elif comp == 'g':
        if you=='s':
            return False
        elif you=='w':
            return True

print("Comp Turn: Snake(s) Water(w) or Gun(g)?")
randNo = random.randint(1, 3) 
if randNo == 1:
    comp = 's'
elif randNo == 2:
    comp = 'w'
elif randNo == 3:
    comp = 'g'

you = input("Your Turn: Snake(s) Water(w) or Gun(g)?")
a = gameWin(comp, you)

print(f"Computer chose {comp}")
print(f"You chose {you}")

if a == None:
    print("The game is a tie!")
elif a:
    print("You Win!")
else:
    print("You Lose!")
Comment

PREVIOUS NEXT
Code Example
Python :: Customize color stacked bar chart matplotlib 
Python :: while loop in python 
Python :: what are args and kwargs in python 
Python :: python list to dataframe as row 
Python :: how to convert pandas price column to integer 
Python :: ipython history 
Python :: upload bytes to s3 python 
Python :: defaultdict python 
Python :: python divide array into n parts 
Python :: Python Split list into chunks using for loop 
Python :: python pyaudio error 
Python :: draw picture in python libraries 
Python :: python jinja2 from string 
Python :: python seaborn violin plot 
Python :: pandas cummin 
Python :: python common elements in two arrays 
Python :: while python 
Python :: get data from kaggle to colab 
Python :: python get object name 
Python :: pandas aggregate dataframe 
Python :: spacy get number of tokens 
Python :: python get type of variable 
Python :: axvline matplotlib 
Python :: remove common rows in two dataframes pandas 
Python :: max value pandas 
Python :: how to take a list as input in python using sys.srgv 
Python :: python bubble 
Python :: concatenating strings in python 
Python :: python merge two list 
Python :: 2d array row and column index 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =