Tag: ELIF

Higher – Rock Paper Scissors – Solution

So when we implemented the code we got something like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#Mr Stratton
 
import random
 
#set up variables
random.seed
object=["Rock","Paper","Scissors"]
playerChoice=""
computerChoice=""
winner=""
 
#Get players choice
playerChoice=object[int(input("Rock - 1\nPaper - 2\nScissors - 3\n"))-1]
 
#Get computer choice
computerChoice=object[random.randint(0,2)]
 
#get winner
if playerChoice=="Rock":
    if computerChoice=="Paper":
        winner="Computer"
    if computerChoice=="Scissors":
        winner="Player"
    if computerChoice==playerChoice:
        winner="Draw"
         
if playerChoice=="Paper":
    if computerChoice=="Scissors":
        winner="Computer"
    if computerChoice=="Rock":
        winner="Player"
    if computerChoice==playerChoice:
        winner="Draw"
         
if playerChoice=="Scissors":
    if computerChoice=="Rock":
        winner="Computer"
    if computerChoice=="Paper":
        winner="Player"
    if computerChoice==playerChoice:
        winner="Draw"
         
 
     
#display winner
print("\n"*10)
print("Player threw",playerChoice)
print("Computer threw",computerChoice)
 
if winner=="Player":
    print("Player is the winner")
     
if winner=="Computer":
    print("Computer is the winner")
     
if winner=="Draw":
    print("Its a draw")

However, although it does follow the design from yesterday it isn’t very effcient.
Can you see a way to make it more effient?

Read more