0

Ok im trying to make a small text based game for school and i made a tiny talents generator as a def function. The problem is that im not able to use the value in another def function and i dont know how. Here's the generator:

def player_dexterite():
   dexterite = random.randrange(0, 26)
   print("Votre dextérité est de: " + str(dexterite))
   if dexterite > 20:
       print("Bravo vous êtes très vif! ")
       player_choice2()
   elif dexterite > 15:
       print("Vous êtes plutôt vif. ")
       player_choice2()
   elif dexterite > 10:
       print("Ça pourrais être mieux. ")
       player_choice2()
   elif dexterite > 5:
       print("Dommage meilleure chance la prochaine fois... ")
       player_choice2()
   elif dexterite < 5:
       print("Bonne chance vous aller en avoir besoin! ")
       player_choice2()

And here's the part where i need the random value:

def armory_1():
   print("Apres environ 100 metre de marche vous entrez dans une piece avec un coffre et une étagère. ")
   print("Une voix vous dit que vous ne pouvez choisir qu'un seul de deux. ")
   choix_2 = input("Voulez vous ouvrir le coffre ou l'étagère?/n (c ou e). ")
   if choix_2 == "c":
       print("Dans le coffre vous trouvez une simple épée, une cotte de maille et une corde.")
       way_1()
   elif choix_2 == "e":
       print("En ouvrant l'étagere une dizaine de serpents vous tombe dessus. (Nécessite +15 dext pour éviter)")
       if player_dexterite() > 14:
           print("Mais heureusement vous êtes assez rapide pour les éviter en courant vers la suite du labyrinthe. ")
           way_1()
       elif player_dexterite() < 15:
           print("Vous n'êtes malheureusement pas asser rapide pour les éviter et mourrez empoisonné. ")
           death_2()

I need to use the value at if player_dexterite() > 14: and elif player_dexterite() < 15:. What can i do?

P.S.: I talk french thats why the story is in french but i prefer to code in partial english.

Thanks for your time.

Benjkf5
  • 3
  • 1
  • if you google: "python use result of function in another function" you will find https://stackoverflow.com/questions/37088457/accessing-returned-values-from-a-function-by-another-function – Scott Stensland Jan 19 '22 at 23:49
  • @ScottStensland Thanks for a better duplicate. I have consistently failed to find one with the site search for this extremely common question. – Karl Knechtel Jan 19 '22 at 23:50
  • @KarlKnechtel I always do my searches using google directly never from inside SO ... suprising as this sounds from a programming site ;-) – Scott Stensland Jan 19 '22 at 23:55
  • Actually, I found an even better one, and *apparently* it was already in my bookmarks. I can't even easily search within those, or even put my own tags on them... ugh. (That question is asked for a slightly more difficult problem; but the answers give a full overview of the general topic, which is the kind of tutorial that these questions call for.) – Karl Knechtel Jan 19 '22 at 23:59

0 Answers0