I'm trying to use functions (something that I am inherently bad at apparentlyXD) and am trying to get the return statement info from the first and then use it in the second. Both are for rolling dice, so the first function is to have the first set returned, which is to be then used in the second function to give the user the option to reroll. What am I doing wrong in this implementation that it's not recognizing the original dieset list?
def rollDie():
die1 = 2
die2 = 2
die3 = 2
die4 = 4
die5 = 5
dieset = [die1,die2,die3,die4,die5]
print(dieset)
return dieset
def reRoll1():
rollDie()
reroll1 = input("Would you like to reroll? Yes or No: ")
if reroll1 == "no":
dieset = [die1,die2,die3,die4,die5]
else:
count = 0
times = int(input("How many die would you like to reroll? "))
while count < times:
whichreroll = input("Reroll die: ")
if whichreroll == "1":
die1 = random.randint(1,6)
else:
die1
if whichreroll == "2":
die2 = random.randint(1,6)
else:
die2
if whichreroll == "3":
die3 = random.randint(1,6)
else:
die3
if whichreroll == "4":
die4 = random.randint(1,6)
else:
die4
if whichreroll == "5":
die5 = random.randint(1,6)
else:
die5
dieset = [die1,die2,die3,die4,die5]
count += 1
print(dieset)
return dieset
reRoll1()
It's telling me "local variable 'die1' referenced before assignment" but rollDie() comes first. If anyone could explain this to me it would be greatly appreciated:D