Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python game 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 terminal game 
Python :: code challenges python 
Python :: normalize numpy array 
Python :: python file to array 
Python :: how to terminate subprocess.call in python 
Python :: python memory usage 
Python :: pandas df to dict 
Python :: opencv loop video 
Python :: Program to find GCD or HCF of two numbers python 
Python :: python input float 
Python :: How to get the first and last values from the dataframe column using a function 
Python :: pd df sample 
Python :: python using random module 
Python :: depth first search python 
Python :: python string trim 
Python :: how to convert csv to excel in python 
Python :: create dict from two lists 
Python :: python get array from json 
Python :: get random number positive or negative python 
Python :: opencv namedwindow 
Python :: numpy diff 
Python :: python convert int to hex string 
Python :: create the dataframe column based on condition 
Python :: paradigm meaning in python 
Python :: how to get scrapy output file in json 
Python :: pytest teardown method 
Python :: download pytz python 
Python :: python verificar se é numero 
Python :: how to have player input in python 
Python :: while activating env show error of unautorize access in vscode 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =