'How do I transfer variables and results from function to function in python? [duplicate]

The set of functions below makes up a small 'game' which at first, picks a random integer for a variable that could be either a Bronze, Silver or Gold Key. It then asks the user to choose a chest to open with the key, if the key is a bronze key it can only open the bronze chest, if the key is a Silver key, it could open both the silver and bronze chest. And if the key is golden, it could open all three chests. the first function follows as:

def return_token():
import random
Key = random.randint(0,100)
KeyType == ""
if Key < 10:
    KeyType = "Golden Key"
elif 10 <= Key <= 40:
    KeyType = "Silver Key"
else:
    KeyType = "Bronze Key"
return result

which has the variable "KeyType", and I have another function such as:

def chest_select():
    Chests = input("Please pick a chest(Bronze, Silver, Gold): ")
    if Chests == "Bronze":
       ChestType = "bronze"

    elif Chests == "Silver":
       ChestType = "Silver"

    elif Chests == "Gold":
       ChestType = "Gold"
    return result

this function has the variable "ChestType", how do I import the results of both functions to a new function such as:

def Results():
   if KeyType == "Golden Key":
      print ("Congratulations, you could open the ", ChestType, "!")

   elif KeyType == "Silver Key":
      if ChestType == "Bronze" and "Silver":
          print ("Congratulations, you could open the ", ChestType, "!")
      else:
         print ("Sorry, you couldn't open that chest.")

   else:
       if ChestType == "Gold" and "Silver":
          print ("Sorry, you couldn't open that chest.")
       else:
          print ("Congratulations, you could open the ", ChestType, "!")

How do I transfer the variables and results from each of the functions to the final function?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source