Question

Python3, please wite the code with comments 2. Write a program to implement the Pokemon game...

Python3, please wite the code with comments

2. Write a program to implement the Pokemon game using your algorithm from

It should ask the user to enter their type and compare it with a randomly chosen computer type and correctly display who wins/ties.

Write an algorithm for resolving a battle among the classic Pokemon types.

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.

Homework Answers

Answer #1

Answer:

# import random module
import random

print("\nWelcome the classic Pokemon Battle Game where you will test the "
      +"strength of your Pokemon against our Computer's Pokemon\n ")

print("Winning Rules of the Pokemon Battle Game as follows: \n"
      + "Fire vs Grass->Fire wins \n"
      + "Grass vs Water->Grass wins \n"
      + "Water vs Fire->Water wins \n")

print("Let the Battle BEGIN.........\n")

while True:
    print("Enter the type of Pokemon: \n 1. Fire \n 2. Grass \n 3. Water \n")

    # take the input from user
    choice = int(input("User turn: "))


    # looping until user enter invalid input
    while choice > 3 or choice < 1:
        choice = int(input("Invalid Type.....\nEnter a valid pokemon type: "))

    # initialize value of choice_name variable
    # corresponding to the choice value
    if choice == 1:
        choice_name = 'Fire'
    elif choice == 2:
        choice_name = 'Grass'
    else:
        choice_name = 'Water'

    # print user choice
    print("User chose: " + choice_name + " type")

    print("\nNow its Computer's turn.......")

    # Computer chooses randomly any number
    # among 1 , 2 and 3. Using randint method
    # of random module
    comp_choice = random.randint(1, 3)

    # looping until comp_choice value
    # is equal to the choice value
    while comp_choice == choice:
        comp_choice = random.randint(1, 3)

    # initialize value of comp_choice_name
    # variable corresponding to the choice value
    if comp_choice == 1:
        comp_choice_name = 'Fire'
    elif comp_choice == 2:
        comp_choice_name = 'Grass'
    else:
        comp_choice_name = 'Water'

    print("Computer chose : " + comp_choice_name + " type")

    print(choice_name + " V/s " + comp_choice_name)
    print("\nLets's GO.......\n\n")

    # condition for winning
    if(choice==comp_choice):
        print("You both chose the same type...\n")
        result="Tie"


    elif ((choice == 1 and comp_choice == 2) or
            (choice == 2 and comp_choice == 1)):
        print("Fire type wins.... ")
        result = "Fire"

    elif ((choice == 1 and comp_choice == 3) or
          (choice == 3 and comp_choice == 1)):
        print("Water type wins....")
        result = "Water"
    else:
        print("Grass type wins....")
        result = "Grass"

    # Printing either user or computer wins or if it's a tie
    if(result=="Tie"):
        print("<== After a fierce battle, the match is a draw ==>\n ")

    if result == choice_name:
        print("\n\n<== User wins ==>\n\n")

    else:
        print("\n\n<== Computer wins ==>\n\n")

    print("Do you want to play again? (Y/N)")
    ans = input()

    # if user input n or N then condition is True
    if ans == 'n' or ans == 'N':
        break

# after coming out of the while loop
# we print thanks for playing
print("\nThanks for playing Pokemon Battle....\nUntil Next Time....\n")

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python Code Please Write an algorithm for resolving a battle among the classic Pokemon types.       ...
Python Code Please Write an algorithm for resolving a battle among the classic Pokemon types.        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. Whomever chose the stronger type is the winner. If...
R-S-P Requirement: - write one C++ program that mimics the Rock-Scissor-Paper game. This program will ask...
R-S-P Requirement: - write one C++ program that mimics the Rock-Scissor-Paper game. This program will ask user to enter an input (out of R-S-P), and the computer will randomly pick one and print out the result (user wins / computer wins). - User's input along with computer's random pick will be encoded in the following format: -- user's rock: 10 -- user's scissor:          20 -- user's paper:            30 -- comp's rock:            1 -- comp's scissor:        2 -- comp's...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT