Update index.md (#21753)

* Update index.md

implementing rock paper scissors  using if elif

* removed sentence
pull/21932/head
Pritom Hazarika 2018-11-05 02:46:21 +05:30 committed by Randell Dawson
parent 833d798ad2
commit 49bf21a3dd
1 changed files with 28 additions and 0 deletions

View File

@ -103,5 +103,33 @@ Output
True
>
```
## Rock-Paper-Scissors Game using if-elif in Python
```python
#importing random library
import random
#make the set of moves
moves = ["rock","paper","scissors"]
keep_playing = "True"
while keep_playing == "True":
cmove = random.choice(moves)
pmove = input("What is your move: rock , paper or scissors?")
print("computer chose ",cmove)
if cmove == pmove:
print("Tie")
elif pmove=="rock" and cmove == "scissors":
print("player Wins")
elif pmove == "rock" and cmove == "paper":
print("computer wins")
elif pmove == "paper" and cmove =="scissors":
print("computer wins")
elif pmove == "paper" and cmove == "rock":
print ("player wins")
elif pmove == "scissors" and cmove =="rock":
print("computter wins")
elif pmove == "scissors" and cmove =="paper":
print ("Player wins")
```