lundi 1 avril 2019

I'm trying to return a randomly generated number in a function so i can do some maths with it

I'm trying to make a function that randomly generates a number so another function can manipulate it.i got it to do what it needs to do but the next function returns an error "variable not defined",I'm guessing that the variable only exist in the scope

I've tried using the return statement at the end but its not returning for some reason

import random

def generator1(): #name of function
    die_total = 0 #used for iteration
    for generator1 in range(2): #loop,generates 2 numbers
        die_roll = random.randint(1,6) #random int generator

        if die_roll % 2 == 0: # depending wether the random is odd or even,5 0r 10 is added
            die_roll += 10
        else:
            die_roll += 5

        die_total += die_roll #used to itterate and obtain a total

    return die_total #the problem,trying to return value of die_total


generator1()

print(die_total)

I expected a random value when i print




Aucun commentaire:

Enregistrer un commentaire