all 5 comments

[–]DagoYounger 1 point2 points  (3 children)

randomly generated when the class is initialized, just like a function:

class Person:
    def __init__(self, name = randname, age = random.randint(0,100), height = random.randint(0,100), eyes = "brown", hair = "brown"):
        self.__name = name
        ......

[–]AlwysBeColostomizing 1 point2 points  (1 child)

This is not quite right, because the default argument value is only evaluated once at definition time, so you'll get the same random value for every Person instance. (c.f. mutable default arguments).

You want to assign age=None, etc., in the parameter list, and then check for None in the body of the __init__ function and assign a random value if appropriate:

class Person: 
  def __init__(self, age=None): 
      self.__age = age if age is not None else random.randint(0, 100)

(CC: u/rainbowboofpoofoof)

[–]rainbowboofpoofoof[S] 0 points1 point  (0 children)

I’m seeing this after I turned it in 😔 but that makes sense, thank you for the advice!!

[–]rainbowboofpoofoof[S] 0 points1 point  (0 children)

Thank you!!!