Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python console 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 :: cli args python 
Python :: python red table from pdf 
Python :: screen.onkey python 
Python :: how to make variable global in python 
Python :: insert row in any position pandas dataframe 
Python :: python datetime get date one week from today 
Python :: how to alight and place ipywidgets 
Python :: python convert image to base64 
Python :: python3 lowercase 
Python :: remove duplicates from tuple python 
Python :: extract text from pdf python 
Python :: socket exception python 
Python :: python math operators 
Python :: confusion matrix for classification 
Python :: np sum 
Python :: Get current cursor type and color Tkinter Python 
Python :: get number of key in dictionary python 
Python :: -- python 
Python :: tkinter icon 
Python :: get body from request python 
Python :: python split by first match 
Python :: python argv 
Python :: settings.debug django 
Python :: python finally keyword 
Python :: pillow python text example 
Python :: keras conv2d batchnorm 
Python :: os path splitext 
Python :: how to write to a specific line in a file python 
Python :: how to add coloumn based on other column 
Python :: start process python 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =