Python无法启动

时间:2016-02-06 00:49:00

标签: python

我是蟒蛇新手,我和朋友正在制作神奇宝贝主题文字冒险!我们已经为开始做了一些代码,但是python只会在运行时启动一秒钟。有什么想法吗?

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")

2 个答案:

答案 0 :(得分:2)

我猜测你是通过打开它而不是通过控制台来使用Windows并运行脚本。当脚本完成执行后,它将关闭窗口。尝试将其添加到脚本的末尾以使其保留:

raw_input('Press Enter to exit')

答案 1 :(得分:0)

祝你好运!为了好玩,这是一个稍微更结构化的版本:

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.")
相关问题