Update index.md (#21753)
* Update index.md implementing rock paper scissors using if elif * removed sentencepull/21932/head
parent
833d798ad2
commit
49bf21a3dd
|
@ -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")
|
||||
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue