Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python terminal game


import random
import time

computerwins = 0
playerwins = 0
ties = 0
end = 0

while True:

    choices = ["rock",
               "paper",
               "scissors"]

    userChoice = raw_input("Rock, Paper, Scissors, or End")

    computerChoice = (random.choice(choices))
    print(computerChoice)

    if userChoice == computerChoice:
        time.sleep(0.5)
        print("Tie!
")
        ties += 1
        end += 1

    elif userChoice == "rock":
        if computerChoice == "paper":
            time.sleep(0.5)
            print("Computer Win!
")
            computerwins +=1
            end += 1

        else:
            time.sleep(0.5)
            print("Player win!
")
            playerwins += 1
            end += 1

    elif userChoice == "paper":
        if computerChoice == "rock":
            time.sleep(0.5)
            print("Player win!
")
            playerwins += 1
            end += 1

        else:
            time.sleep(0.5)
            print("Computer win!
")
            computerwins += 1
            end += 1

    elif userChoice == "scissors":
        if computerChoice == "rock":
            time.sleep(0.5)
            print("Computer win!
")
            computerwins += 1
            end += 1

        else:
            time.sleep(0.5)
            print("Player win!
")
            playerwins += 1
            end += 1

    elif userChoice == "end":
            choices.append("end")
            print("
Great game!
")
            print("Total score for computer: ", computerwins, "wins!")
            print("Total score for player: ", playerwins, "wins!")
            print("Total ties: ", ties, "ties!")
            time.sleep(2)
            break
Comment

PREVIOUS NEXT
Code Example
Python :: show distribution pandas coloumns 
Python :: add to a list python 
Python :: uppercase string python 
Python :: square root python 3 
Python :: checksum python 
Python :: extract a column from a dataframe in python 
Python :: list files in http directory python 
Python :: check if something is nan python 
Python :: python declare variables from dictionary 
Python :: what is a slug 
Python :: tensorflow to numpy 
Python :: instagram python bot 
Python :: how to get a int from string python 
Python :: remove first item form dictionary python 
Python :: sum of a numpy array 
Python :: np.where 
Python :: plus in python 
Python :: python convert input into lowercase 
Python :: how to put python code on a website 
Python :: for loop from n to 1 in python 
Python :: python yeild 
Python :: gradient boosting regressor 
Python :: check if list elememnt in dataframe column 
Python :: select columns pandas 
Python :: tkinter delete toplevel 
Python :: Matplotlib inside Jupyter | Jupyter generate graphs. 
Python :: oserror: invalid cross-device link 
Python :: python save button 
Python :: telegram bot webhook python 
Python :: python remove common elements between two lists 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =