Week 5


Today I went through the classes tutorial on w3schools (https://www.w3schools.com/python/python_classes.asp)

I wrote my own code to get an understanding of how classes work in Python.

In this code I define a new class for a diary. I then create an object from this class which takes a list of events and a list of lessons. I then use various lines of code to interact with this object. I made a variable that takes an input for a new event. This then gets added to the list in the object.

Code output:


Week 5 Activities

1. Returning multiple values


Output:

The original values are: (5.8, 3.5, 6.3)

The sorted list is: [3.5, 5.8, 6.3]


2. Populating Scenes with Assets

In this task I experimented with the random module in python. This module is useful when needing a to randomize a data set or generating random values.


3. Maya Commands

import maya.cmds

The import command is used to import external modules which gives the programmer access to extra functionality.

cmds.polyCube()

This command can be used to create a cube and by replacing 'cube' many other shapes can be generated in maya.

cmds.setAttr("my_circle.rx", 90)

This command is used to change the attributes of existing shapes. For example 'cmds.setAttr("my_circle.rx", 90)' rotates the shape 90 degrees in the x axis.

cmds.move(2, 2, 2, my_shape)
cmds.rotate(2, 2, 2, my_shape)
cmds.scale(2, 2, 2, my_shape)

These commands give access to the common transform tools used in maya. With these commands, a programmer can accurately manipulate existing shapes easily.

maya.makeIdentity(my_shape, apply = True)

This command is used to freeze the transforms in maya.

maya.select(my_shape)
maya.delete(my_shape)

These commands are used to select and delete shapes in maya.

maya.parent(my_shape, child_shape)

This command can be used to parent the object in the second arguement to the object in the first.


5. Random Numbers

import random
for i in range(100):
    print(random.randint(10,590))
running = 100
while running != 0:
    print(random.randint(10,590))
    running -= 1

Here is the code utilizing two different iterables: a for loop and a while loop.

In order to test this printed 100 times, a few lines can be added to give a readable output.

For example:

count = 0
for i in range(100):
    print(random.randint(10,590))
    count += 1
print(f"The code ran {count} times.")

In this example, I have a running count that gives an output after the loop has ran.

Output:

The code ran 100 times.


6. User Input

int_var = 0 
def enter_number():
    int_var = input("Please enter a number: ")
    return int_var
user_num = enter_number()
print(f"The number you entered was: {user_num}")

Above is one example of a function asking for a user input and returning it.

def user_input_2():
    return input("Please enter a number: ")
print(f"You entered: {user_input_2()}")

Here is a shortened version.

Leave a comment

Log in with itch.io to leave a comment.