How to make Rock , Paper , Scissor Game with Python
Full Code:
from random import randint
t = ["rock", "paper", "scissor"]
computer = t[randint(0,2)]
player = False
while player == False:
player = input("rock, paper, scissor?")
if player == computer:
print("Tie!", "You:", player, "computer", computer)
elif player == "rock":
if computer == "paper":
print("You lose!", "You:", player, "computer", computer)
else:
print("You win!", "You:", player, "computer", computer)
elif player == "paper":
if computer == "scissor":
print("You lose!", "You:", player, "computer", computer)
else:
print("You win!", "You:", player, "computer", computer, "You:", player, "computer", computer, "You:", player, "computer", computer)
elif player == "scissor":
if computer == "rock":
print("You lose", "You:", player, "computer", computer, "You:", player, "computer", computer)
else:
print("You win!", "You:", player, "computer", computer)
else:
print("That's not a valid play. Check your spelling!")
player = False
computer = t[randint(0,2)]
First step : To import functions
>> from random import randint
Second step:There are there plays that you can and computer can play are "Rock" "Paper" "Scissor"
>> t = ["rock" "Scissor" "Paper"]
Third step : to set the computer's command
>> computer = t[randint(0,2)]
player = False
Fourth Step : To build logic to predict the Command...
>> while player == False:
player = input("rock, paper, scissor?")
if player == computer:
print("Tie!", "You:", player, "computer", computer)
elif player == "rock":
if computer == "paper":
print("You lose!", "You:", player, "computer", computer)
else:
print("You win!", "You:", player, "computer", computer)
elif player == "paper":
if computer == "scissor":
print("You lose!", "You:", player, "computer", computer)
else:
print("You win!", "You:", player, "computer", computer, "You:", player, "computer", computer, "You:", player, "computer", computer)
elif player == "scissor":
if computer == "rock":
print("You lose", "You:", player, "computer", computer, "You:", player, "computer", computer)
else:
print("You win!", "You:", player, "computer", computer)
else:
print("That's not a valid play. Check your spelling!")
player = False
computer = t[randint(0,2)]
Now that sit ...
Congratulations, You have made your first game..
Full Code:
Output:
rock, paper, scissor?rock
You lose! You: rock computer paper
rock, paper, scissor?paper
Tie! You: paper computer paper
rock, paper, scissor?scissor
You win! You: scissor computer paper
rock, paper, scissor?rock
You lose! You: rock computer paper
rock, paper, scissor?scissor
You win! You: scissor computer paper
rock, paper, scissor?paper
Tie! You: paper computer paper
2 Comments
Very nice
ReplyDeleteThank you😊
DeleteIf You Guys Have Any Doubt So, Please Comment Down Below !