mardi 15 janvier 2019

I want to print a randomly generated number inside my class but keep getting errors

I am getting a name error, randint not defined when trying to print a random number from a class method.

class Deck:
    import random
    def __init__(self,choice,card = 0):
        self.choice = choice
        self.card = card
    def deck(self): 
        if self.choice == 1:
            print((randint(1,5)))

I want it to print a random number 1-5, I can achieved the result by creating a class variable with a random number assigned to it, I would still like to know why I can not just generate random numbers inside the methods.




Aucun commentaire:

Enregistrer un commentaire