Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python minigame


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 download file from ftp 
Python :: how to exit program in python 
Python :: bringing last column to first: Pandas 
Python :: create custom exception python 
Python :: title tikinter 
Python :: make poetry env 
Python :: python beginner projects 
Python :: python logging basicConfig+time 
Python :: python - regexp to find part of an email address 
Python :: rotating circular queue in python 
Python :: python check phone number 
Python :: insert single value in dataframe using index 
Python :: convert string to lowercase python 
Python :: dfs in python 
Python :: how to get value from set in python 
Python :: tkinter pack grid and place 
Python :: import discord 
Python :: concatenate list of strings 
Python :: file methods in python 
Python :: is tuple immutable in python 
Python :: convert list to tuple python 
Python :: python generate pdf from template 
Python :: if settings.debug 
Python :: what is a print statement 
Python :: only read some columns from csv 
Python :: to string python 
Python :: python file modes 
Python :: kpss test python 
Python :: binary to string python 
Python :: gzip folder python 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =