おそらくトピックから理解したように、私はかなり初心者です。とにかく、Pythonは呼び出しを無視しているように見えるので、別の関数内から関数を呼び出すことに問題があります。
これはif
私の関数内からのものですy
:
if clas == "warrior":
strenght, toughness = warrior()
print "Your strenght is %d." % strenght
print "Your toughness is %d." % toughness
return strenght, toughness
warrior_journey()
y
ここで return を使用して、これらの値を関数ブロックの外でグローバル変数に割り当てます。
char_str, char_tough = character()
今、私のy
関数はwarrior()
問題なく呼び出しますが、 を無視しwarrior_journey()
、出力strenght, toughness
して終了します。おそらく と関係がありますがreturn
、これに関して役立つものは何も見つかりません。
「y」または「文字」機能コード全体を次に示します。
def character():
name = raw_input("Welcome, please give the name of your character:\n> ")
if name.isalpha() == True and len(name) != 0 and len(name) != 1:
print "Welcome again %s!" % name
else:
exit("This isn't a proper name")
clas = raw_input("Great, now choose your class (warrior, rogue, thief):\n> ").lower()
if "warrior" in clas or "rogue" in clas or "thief" in clas:
print "Your class is %s." % clas
else:
exit("You have only three choices listed above, read them again")
if clas == "warrior":
strenght, toughness = warrior()
print "Your strenght is %d." % strenght
print "Your toughness is %d." % toughness
warrior_journey()
return strenght, toughness
elif clas == "rogue":
strenght, toughness = rogue()
print "Your strenght is %d, and your toughness is %d." % (strenght, toughness)
return strenght, toughness
elif clas == "thief":
strenght, toughness = thief()
print "Your strenght is %d, and your toughness is %d." % (strenght, toughness)
return strenght, toughness
それから、私は持っています:
char_str, char_though = character()
さらに、問題のある関数の warrier_journey:
def warrior_journey():
print "You wake hangovered in the woods, sun rays dancing on your face"
print "as you regain parts of your consciousness you notice that, happily, your weapon is still at your side"
print "You have an open world before you, in which direction do you stumble (north, south, east, west)?"
direction = raw_input("> ").lower()
if direction == "north" or direction == "n":
warrior_north()
elif direction == "south" or direction == "s":
warrior_south()
elif direction == "east" or direction == "e":
warrior_east()
elif direction == "west" or direction == "w":
warrior_west()
else:
print "This is not a valid direction, perhaps you should sleep some more."
それはまだ「wip」であるため、warrior_journey は何も返さないか、別の関数に送信されませんが、少なくとも「character」関数の呼び出しによって出力される必要がありますね。