Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python example


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 :: python console game 
Python :: show distribution pandas coloumns 
Python :: pandas cartesian product 
Python :: python remove empty values from list 
Python :: Video to text convertor in python 
Python :: merge all mp4 video files into one file python 
Python :: github python api 
Python :: python get the intersection of two lists 
Python :: add two column values of a datframe into one 
Python :: sharpdevelop pause python code 
Python :: remove rows from pandas 
Python :: python verify if string is a float 
Python :: list comprehension python if else 
Python :: depth first search in python 
Python :: Python Tkinter Text Widget Syntax 
Python :: Week of the year Pandas 
Python :: train-test split code in pandas 
Python :: python read excel 
Python :: integral python 
Python :: selenium click on item in a list 
Python :: ModuleNotFoundError: No module named 
Python :: python bubble sort 
Python :: make a condition statement on column pandas 
Python :: itertools .cycle() 
Python :: create a virtualenv python3 
Python :: how to use query_params in get_object djangorestframework 
Python :: python cut string to length 
Python :: fetch row where column is missing pandas 
Python :: neural network hyperparameter tuning 
Python :: static files in django 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =