In: Computer Science
The user should select a type of either fire, water or grass. The computer should randomly select one of those three types as well.
To determine if the user or computer wins, or if it is a draw: fire is stronger than grass, grass is stronger than water, and water is stronger than fire. Whoever chose the stronger type is the winner. If both chose the same type it is a draw.
python
CODE IN PYTHON:
import random
#taking input from the user
userChoice = input("Enter pokeman type(fire/grass/water)")
#validating the input
if(userChoice!="fire" and userChoice!="grass" and
userChoice!="water"):
print("Invalid input... next time please enter valid
input...")
exit(0)
#generating the computer choice
n = random.randint(1,4)
computerChoice = " "
if(n==1):
computerChoice = "fire"
elif(n==2):
computerChoice = "grass"
elif(n==3):
computerChoice = "water"
#displaying the winner
print("computer choice is:"+computerChoice)
if(userChoice=="fire" and computerChoice == "grass"):
print("User wins")
elif(computerChoice=="fire" and userChoice == "grass"):
print("Computer wins")
elif(userChoice=="grass" and computerChoice == "water"):
print("User wins")
elif(userChoice=="water" and computerChoice == "grass"):
print("Computer wins")
elif(userChoice=="water" and computerChoice == "fire"):
print("User wins")
elif(userChoice=="fire" and computerChoice == "water"):
print("Computer wins")
else:
print("Its Draw")
OUTPUT: