Posted December 07, 2022 by up2122682
First I wrote:
import maya.cmds
maya.cmds.polySphere()
into the command line, after hitting enter it created a polySphere primitive to my scene:
Next I executed the same code however this time, in the script editor:
Next I created a While loop that counts from 1 - 10 in intervals of 3:
The while checks whether x is less than 11, if so it will print the value of x, next it will add 3 to the value of x. This repeats until the value of x is 11 or above.
Function to convert degrees Celsius to Fahrenheit:
I then decided to allow the user to input the temperature instead of having me set it:
I then added a while loop to make the code run indefinitely:
I then realised that the code worked if the user inputs an Integer or a Float however if they input a String an error occurs. So I made changes to account for this. If a string is entered, "Please enter a number is displayed":
Here I modified some old code that does the math related to different scored when grading. I added functions to modularise the code:
Here is a function checklist to help check whether the function will work:
1. Did you start your function definition with def?
2. Does your function name have only characters and _ (underscore) characters?
3. Did you put an open parenthesis ( right after the function name)?
4. Did you put your arguments after the parenthesis ( separated by commas)?
5. Did you make each argument unique (meaning there was no duplicated names)?
6. Did you put a close parenthesis ) and a colon : after the arguments?
7. Did you indent by four spaces all lines of code you want in the function? No more, no less?
8. Did you “end” your function by going back to writing with no indent?
And when you run (“use” or “call”) a function, check these things:
1. Did you call/use/run this function by typing its name?
2. Did you put the (-character after the name to run it?
3. Did you put the values you want into the parentheses separated by commas? 4. Did you end the function call with a )-character?