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 :: cs50 templating urls 
Python :: bucket dataframe into ranges 
Python :: Return a sorted copy of the list. Does not modify original list. 
Python :: discord.py find user by name 
Python :: japanese translator google 
Python :: pyton get minimum value of array 
Python :: face sentiment 
Python :: pe039 
Python :: how to calculate the age from date of birth in python 
Python :: python arithmetic operation with list 
Python :: how to run a seaborn plot on pycharm 
Python :: prime number program in python using function 
Python :: Dynamically limiting queryset of related field 
Python :: pinyin to pinyin numbers python 
Python :: how to convert comma separated string to list in python 
Python :: handdle close window action in pyqt5 
Python :: regex emaple py 
Python :: Flask migration method, see the artcle for more info 
Python :: u00a0 
Python :: how to export schema in graphene django 
Python :: python .exe long start 
Python :: kivy lang 
Python :: how to print a text in python 
Python :: generate-thumbnails-in-django-with-pil 
Python :: torch.unsqueze 
Python :: python filter function 
Python :: pivot_table indexing 
Python :: python for in 
Python :: convert float to booelan 
Python :: Define a python function day_of_week, which displays the day name for a given date supplied in the form (day,month,year). 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =