简体   繁体   中英

Python won't launch

I am new to python and me and a friend are making a Pokémon themed text adventure! We've made some code for the start, however python will only launch for a second when it runs. Any ideas?

trainer=raw_input("Hello, I am Professor Oak. Today you may pick your Pokémon. But first, what is your name?")
starterpokemons= ['Charmander','Squirtle','Bulbasaur']
print("Hello" + user +"Here, pick from " + starterpokemons[0] + "; a fire type," + starterpokemons[1] + "; a water type or " + starterpokemons[2]"; a grass type.")
choice = input("Select your Pokémon: ")
if choice in starterpokemons:
starterpokemon = items[choice]
else:
print("Uh oh, That is not a Starter Pokémon")

I'm guessing you're using windows and running the script by opening it rather than through the console. When the script has finished executing it will close the window. Try adding this to the end of your script to make it stay:

raw_input('Press Enter to exit')

Good luck! For fun, here is a slightly more structured version:

class Pokemon:
    def __init__(self, name, type_):
        self.name = name
        self.type_ = type_

pokemons = [
    Pokemon('Charmander', 'fire'),
    Pokemon('Squirtle',   'water'),
    Pokemon('Bulbasaur',  'grass')
]

def main():
    print("Hello, I am Professor Oak. What is your name?")
    name = raw_input()
    print("Hello, {}".format(name))

    print("Here are the starter pokemons:")
    for num,pok in enumerate(pokemons):
        print("{}: {}, a {} type".format(num, pok.name, pok.type_))
    choice = int(raw_input("Which will you train first? "))

    my_pokemon = pokemons[choice]
    print("You chose {}!".format(my_pokemon.name))

if __name__ == "__main__":
    main()
    raw_input("Press Enter to quit.")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM