Week 5
///1. Returning multiple values
Activity 1. (creating a function named myOrder, which takes three floats and returns them ordered from the smallest to the largest.)
def myOrder(x,y,z): #Defines a function with three floats
#To approach this, I made an if statement for every possible outcome in order
if (x>y) and (y>z):
return x,y,z
elif (y>x) and (x>z):
return y,x,z
elif (z>y) and (y>x):
return z,y,x
elif (y>z) and (z>x):
return y,z,x
elif (z>x) and (x>y):
return z,x,y
elif (x>z) and (z>y):
return x,z,y
x,y,z = myOrder(2,30,29)
print(x,y,z) #prints the numbers in order
#This is very lengthy, I am sure there is a much more efficient way to do this
/// 3. Maya Commands
maya.cmds #imports maya commands
Box01=ma.polyCube(name="Box01") #Creates a 1x1 cube at 0,0,0
Box02=ma.polyCube(name="Box02", height=2, width=2, depth=2) #Creates a 2x2x2 cube at 0,0,0
Circle01=ma.circle(name="Circle01", radius=5) #Creates a circle with radius 5 at 0,0,0. Used to manually handle the radius of a circle.
ma.setAttr("Circle01.rx", 90) #To set the circle's x axis rotation to 90
ma.move( 2, 0, 0, Box02) #Moves Box02 to 2,0,0
ma.rotate(45,0,0,Box02) #To rotate Box02 by 45 degrees in the x axis
ma.scale(1, 1.5, 1.5, 1.5, Box02) #To scale Box02 by 1.5 in the x and y axis
ma.makeIdentity(Box02, apply=True) #To freeze transformations Box02
ma.select(Box01) #To select Box01
ma.delete(Box01) #To delete Box01
ma.parent(Box02, Circle01) #Parents Box02 to Circle01
///5. Random Numbers
a) Write a script on your Python executor using a for-loop to generate and print out 100 random integers between 10 and 590:
b) Create while-loop to generate and print out these random integers
import random
#for loop that creates 100 numbers
for x in range (99):
x = random.randint(10,590)
print(x) #prints these random 100 numbers
#I don't understand why we would need a while loop to print these 100 numbers, i think it's correct without it
///6. User Input
x=0 # first declares an integer variable and sets its value to 0
print('Enter your number:') #asks the user for a number
x = input() #inputs a number
print('Hello, this was your number ' + x) #shows the user the number that they assigned to the variable
Leave a comment
Log in with itch.io to leave a comment.