testing my knowledge of class python

I fiddled with making a class and using it,  I think I got a grasp, but moving on.
Here are the two files:

the class file:


--Start code block--

class Variables(object):

    def __init__(self, doors, strength_of_door, name_of_door):
        self.doors = doors
        self.strength_of_door = strength_of_door
        self.name_of_door = name_of_door





    def print_variables(self):
        print(self.doors)
        print(self.strength_of_door)
        print(self.name_of_door)


    def create_door(self):
        print("Creating New Door: ")
        print(f""" door number = {self.doors} \n strength of door
         = {self.strength_of_door} \n name of door = {self.name_of_door}.""")





--End code block--

This is my test file:
--Start code block--


from Class_doors import Variables

# this is creating the variables attributed to wooden door
wooden_door = Variables(10, 20, "wooden")

# this will print off a message about the door
Variables.create_door(wooden_door)

# this will print the attributes of the wood door
Variables.print_variables(wooden_door)

# this will create attributes to steel door
steel_door = Variables(2, 100, "steel")

# this will print those attributes
Variables.print_variables(steel_door)

# this is giving the identity of the objects
print(f" steel door = {steel_door}")
print(f" wooden door = {wooden_door}")

# creating a new door
steel_door1 = Variables(3, 200, "forged steel")

# creating variables for a new door
mystery_door = 9
aluminum = 2000

# assigning the variables to a strange door
strange_door = Variables(mystery_door, aluminum, "mystery")

# printing the attributes/variables of the strange door
Variables.print_variables(strange_door)

# testing a door that is not right:
yellow_door = "not created"

def describe_door(arg):
    kind_of_door = arg
    try:
        Variables.print_variables(kind_of_door)
    except AttributeError:
        print("door not created yet.")



# wooden door was created, it will run
describe_door(wooden_door)



# yellow door was not created 
describe_door(yellow_door)
--end code block--




Comments

Popular posts from this blog

JavaScript Ascii animation with while loops and console.log

playing with trigonometry sin in pygame

JavaScript and a Matrix