Aug-21-2018, 03:45 AM
I'm brand new to programming and wanted to write a simple Pokemon game in Python. I got to the point where you can choose a Pokemon and it generates a random wild pokemon encounter, but for some reason, my while statement to see if you want to fight or run asks you twice and I have no idea why!
thanks :D
thanks :D
import random import time from typing import List wild_pokemon = ["Caterpie", "Metapod", "Butterfree", "Weedle"] class bulbasaur: name = "Bulbasaur" health = 100 moves = ["Cut", "Razor Leaf"] class charmander: name = "Charmander" health = 100 moves = ["Tackle", "Ember"] class squirtle: name = "Squirtle" health = 100 moves = ["Tackle", "Bubble"] class pikachu: name = "Pikachu" health = 100 moves = ["Quick Attack", "Thundershock"] def intro(): print("Hello, there. Glad to meet you!") time.sleep(2) print("Welcome to the world of Pokémon!") time.sleep(2) print("My name is OAK. People affectionately refer to me as the Pokémon Professor.") time.sleep(4) print("This world is inhabited far and wide by creatures called Pokémon.") print("For some people, Pokémon are pets. Others use them for battling.") time.sleep(4) print("As for myself... I study Pokémon as a profession.") time.sleep(4) print("But first, tell me a little about yourself...") # Ask player for name player_name = input("What is your name? \n") print(player_name + "! " + "Your very own Pokémon legend is about to unfold!") def part_one(): # Prompt Pokémon selection player_pokemon = input("What Pokémon will you choose: Bulbasaur, Charmander, or Squirtle?: \n") # Validation while player_pokemon.lower() != "bulbasaur" and player_pokemon != "charmander" and player_pokemon != "squirtle": player_pokemon = input("What Pokémon will you choose: Bulbasaur, Charmander, or Squirtle? ") print("You have chosen", player_pokemon.capitalize()) time.sleep(1) print('\n') print('...') print('\n') time.sleep(1) # Opponent Pokémon selection opponent = random.choice(wild_pokemon) print("Wild", opponent, "appeared!") time.sleep(1.5) print("what will", player_pokemon, "do?\n") # this is the part that I need help with :) def choice(): path = "" while path != "fight" and path != "run": path = input("what will you do?\n(FIGHT or RUN)\n") if path == "fight": print("You have chosen to fight!") elif path == "run": print("You have chosen to run") return path def check_battle(): if choice() == "fight": in_battle = True else: in_battle = False print() part_one() choice() check_battle() input("Press enter to close")