我在python中制作这个游戏口袋妖怪,但非常简单的版本。到目前为止,这是我的代码。我想要做的是,在Torchik晕倒之后,我希望它能够循环回到第一线,如果他是一个男孩或一个女孩,并且必须再次经历一切。我该怎么做呢?
print("Now,", name, "are you a boy or a girl?")
gender=input()
print("Enough with the introduction, let us go to the world of Pokemon!")
enter=input("Press enter to continue")
print("You will now pick your starting Pokemon", name,"!")
if gender== 'boy' or gender== 'Boy':
print("You have three choices for your starting Pokemon.")
starterP=input("Would you rather Torchik, Mudkip, or Bulbasaur? Choose wisely.")
if starterP=='Torchik' or starterP=='torchik':
print("You have picked Torchik!")
print("Now, what region would you like to go to first? Kanto, Hoenn, Magiko, Yanto, or Kati?")
region1=input()
if region1=='Kanto' or region1=='kanto':
print("Kanto it is!")
print("You are currently facing the Pokemon Master for the Kanto region!")
attack=input("Would you like to use cut and hurt his Pokemon?")
if attack=='yes' or attack=='Yes':
print("Torchik attacked the foe Pokemon! The foe has fainted!")
if attack=='no' or attack=='No':
print("The foe has attacked you! Fellow Torchik has fainted!")
print("Game over!")
答案 0 :(得分:0)
以下是loop的工作原理:
while <condition>:
do_something()
或
for running_variable in <iterator>:
do_something(running_variable)
这可以像:
一样使用running_total = 0
for i in [1,2,3,4,5,6,7,8,9,10]:
running_total = running_total + i
# this is running_total += i
# this is all just sum(range(1,11)) but....
或
while True: # True is, unsurprisingly, always True
print("I'm an infinite loop!")
无限循环可能适合这样的事情,因为您可以使用几个关键字来操纵它们:continue
和break
。我会建议,但我会留给您实施。