0% found this document useful (0 votes)
29 views3 pages

Python Game (4.0.0)

Uploaded by

Elsa Lo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Python Game (4.0.0)

Uploaded by

Elsa Lo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import random, time

Choices = ['Rock', 'Paper', 'Scissor'] #Rock, Paper or Scissor


player_point = 0 #Player's point(s)
robot_point = 0 #Robot's point(s)
number = 0 #Where to stop the loop

print("Information of the game:") #Rules of the game


print("\nYou will play with a robot.")
print("Who first get 3 points win.") #How to win
print('''
Rock --> Scissor
Scissor --> Paper
Paper --> Rock
**No point get if your choice is same as robot's choice''') #How to win

#Control the chance *what the robot choose*


def percentage_change(Targetlist, First_chance_change, Second_chance_change, Third_chance_change,
BaseNumber):

StorageList = [] #Create a list

for i in range(100): #Loop one hundred times (100%)


Number = random.randrange(0, BaseNumber+1) #Create a random number

if (Number <= First_chance_change): #If the first number is bigger than the Random-Number,
StorageList.append(Targetlist[0]) #The first 'box' in Targetlist will storage in to the 'StorageList'

elif (Number >= Second_chance_change and Number <= Third_chance_change): #If the second number
is smaller and the third number is bigger than the Random-Number,
StorageList.append(Targetlist[1]) #The second 'box' in Targetlist will storage in to the
'StorageList'

elif (Number > Third_chance_change): #If the third number is smaller than the Random-Number,
StorageList.append(Targetlist[2]) #The third 'box' in Targetlist will storage in to the 'StorageList'

return list(StorageList) #The result is a list and those 'boxes' in the StorageList

#Print out the point(s) got


def points():
return print("\nYour point: {}".format(player_point)), print("Robot's point: {}".format(robot_point))

#Determine who win


def result():
global number
if (player_point == 3):
number = 1
return print('\nPlayer win!')

elif (robot_point == 3):


number = 1
return print('\nComputer win!')

while True: #A loop


if (number == 0): #Determine whether to stop the game
robot = random.choice(percentage_change(Choices, 30, 31, 73, 100)) #The robot choose "Rock, Paper
or Scissor"
player = input('\nRock, Paper or Scissor:').capitalize() #Player choose "Rock, Paper or Scissor"
if player in Choices: #Determine whether the answer player's input is in the Choices's 'Boxes', if no...
time.sleep(0.7)
print('Robot: {}'.format(robot)) #Show you and robot choice
print('You: {}'.format(player))
time.sleep(0.2)

if (player == robot): #If player's choice is equal to robot's choice,


print('Draw!') #Draw!!
points()

elif (player == 'Rock' and robot == 'Scissor'): #If player's choice is equal to "Rock" and robot's choice
is equal to "Scissor",
print('You win!') #Player win
player_point += 1 #Player's point increase by 1
points()
result()

elif (player == 'Scissor' and robot == 'Paper'): #If player's choice is equal to "Scissor" and robot's
choice is equal to "Paper",
print('You win!') #Player win
player_point += 1 #player's point increase by 1
points()
result()

elif (player == 'Paper' and robot == 'Rock'): #If player's choice is equal to "Paper" and robot's choice
is equal to "Rock",
print('You win!') #Player win
player_point += 1 #player's point increase by 1
points()
result()

elif (robot == 'Rock' and player == 'Scissor'): #If robot's choice is equal to "Rock" and player's choice
is equal to "Scissor",
print('Robot win!') #Robot win
robot_point += 1 #robot's point increase by 1
points()
result()

elif (robot == 'Scissor' and player == 'Paper'): #If robot's choice is equal to "Rock" and player's
choice is equal to "Scissor",
print('Robot win!') #Robot win
robot_point += 1 #robot's point increase by 1
points()
result()

elif (robot == 'Paper' and player == 'Rock'): #If robot's choice is equal to "Rock" and player's choice
is equal to "Scissor",
print('Robot win!') #Robot win
robot_point += 1 #robot's point increase by 1
points()
result()

else:
print('No other letter or special word.') #If no, print this.

else: #End the game.


break

You might also like