# Rhino Python Lecture 2016 | DAY1

### Contents

- Intro
- What’s RhinoPython?

- UI
- Start up RhinoPython editer
- User Interface
- “#” – Comment Out

- Variables
- Types and Substitution
- Check Variables – Print statement
- Four arithmetic operations

- Practice #1
- Editing Variables and Arithmetic Operations

- Iteration
- For Loop Statements

- Practice #2
- Describing mathematical sequence

### 1. Intro

#### 1.1. What’s RhinoPython?

official:

http://developer.rhino3d.com/guides/rhinopython/what_is_rhinopython/

If you finish all of the training, you will be able to …

#1:Create a original GHPython component by yourself.

#2:Speed up of the GH’s processing by a multi-threaded.

#3:Understand the simulation method of the object-oriented program.

### 2. UI

##### 2.1. Start up RhinoPython editer

Please enter following characters at Rhino5’s command line —

EditPyrthonScript

##### 2.2. User Interface

##### 2.3 “#” – Comment Out

# Anything after the # is ignored by python. # For writing memorandum of code #accepted print "test" #ignored #print "test"

### 3. Variables

#### 3.1. Types and Substitution

Programs are series of procedure to deal with bunch of variables. Variables are the main elements in computer programs and are sometimes compared to boxes to store data. Every variable have its data type.

“=” is a relational operator that indicates right-hand side and left-hand side are equal in mathematics, but is a operator to substitute right-hand side for left-hand side in programming.

#There are several several data types. #Followings are popular variables in Python: #int - Integer variables i = 1 #float - floating-point arithmetic f = 0.001 #string - Text variables s = "text" #boolian - True/False variables (binary values) b1 = True b2 = False

#### 3.2. Check Variables – Print statement

#Check variables by printing at console. #int - Integer variables i = 1 print i #float - floating-point arithmetic f = 0.001 print f #str - Text variables s = "text" print s #bool - True/False variables (binary values) b1 = True b2 = False print b1, b2

#### 3.3. Four arithmetic operations

#Description method of arithmetic operations: #Assume variable x holds 10 and variable y holds 4, x = 10 y = 4 #Add two numeric values add = x + y print add #Subtract two values sub = x - y print sub #Multiply two values mul = x * y print mul #Divide two values div = x / y print div #Divide two numbers and return only the remainder rem = x % y print rem #Use "()"-brackets b1 = x + y * 2 b2 = (x + y) * 2 print b1 print b2

### 4. Practice #1

#### 4.1. Editing Variables and Arithmetic Operations

Find the solution of mathematical formulas by defining Variables and Arithmetic Operations.

#### #Example

# example a = 55 b = 25 c = 59 d = 25 ans = a*b - c*d print ans # = -100

—

#### #Exercise1

—

#### #Exercise2

### 5.Iteration

#### 5.1.For Loop Statements

For loops are traditionally used when you have a piece of code which you want to repeat “N” number of times.

#The variable "i" starts out by "0" and it is incremented by "1" until it becomes 1 less than "N". #In other words, "N" is the total amount that you want to increment up to. a = 0 N = 10 for i in range(N): a = a + i print i, a #FIY - Advanced writing #The variable "i" starts out by being equal to "A" and it is incremented by "N" until it becomes 1 less than "B". A = 2 B = 10 N = 2 for i in range(A,B,N): print i

### 6. Practice #2

#### 6.1. Describing mathematical sequence

Find the solutions of mathematical sequence by defining For Loop Statements.

#### #Example:Arithmetic progression

Arithmetic progression:https://en.wikipedia.org/wiki/Arithmetic_progression

#Example:Arithmetic progression d = 2 #the common difference of successive members a1 = 5 #the initial term of an arithmetic progression for n in range(100): an = a1 + n*d #Arithmetic progression print an

—

#### #Exercise:Fibonacci number

Fibonacci number:https://en.wikipedia.org/wiki/Fibonacci_number