# It’s Yearbook Day!

Yearbooks are here and will be distributed later today.

Didn’t order one? It’s not too late! See the flyer below or click the link to sign up at Tree Ring and order yours today for delivery in 2-3 weeks straight to your home. Softcover books are \$20 and hardcover are \$6.95. Shipping is approximately \$8.

You will have the option of creating 2 personalized pages using your own photos, but you may also opt to order a standard, non-customized book. You will need an Adobe Flash enabled browser to create custom pages.

Late Yearbook Flyer

# Join Repl.it

You’ll need to join my repl.it classroom for the next few class sessions. You may use this tool the rest of your lives… It’s extremely handy and allows you to run code in most programming languages and even build web pages for testing!

# Day 3 Program

Today we wrote our Nspire version of a dice roll simulation. Here’s an example of the function that simulated 1 or more trials of 6 dice.

```Define dice(trials)=
Func
Local i,roll,counts,total_rolls
total_rolls:=6*trials
counts:={0,0,0,0,0,0}
For i,1,total_rolls
roll:=randInt(1,6)
counts[roll]:=counts[roll]+1
EndFor
Return counts
EndFunc```

And here’s the program that ran multiple trials to determine the experimental probability of rollling 1,2,3,4,5,6 each the same number of times.

```Define rollsim(trials,c)=
Prgm
Local i,counter,roll
counter:=0
For i,1,trials
roll:=dice(c)
If roll={1,1,1,1,1,1}*c Then
counter:=counter+1
EndIf
EndFor
Disp "all the same: "&string(counter)
Disp "EP:"&string(((counter)/(trials))*100.)&"%"
Return ((counter)/(trials))*1.
EndPrgm```

# Day 2 Program — Guess!

Here’s at least one way to make the program from class. I’ve added some spaces to make it more readable, but they’re NOT required on the calculators.

```Define guess()=
Prgm
Local num, trial, guessed, guesses

guesses:=0
guessed:=false

num:=randInt(1,10)
Disp num

While not guessed
Request "Guess (1-10)?",trial,0
guesses:=guesses+1

If trial=num Then
guessed:=true
ElseIf trial<num Then
Disp "Too low!"
ElseIf trial>num Then
Disp "Too high!"
EndIf
EndWhile

local prt
prt := string(guesses)
Disp "You got it in" & prt & " guesses."

EndPrgm```

# Nspire Programming notes

### To create a new program:

• Create a new document
• Insert a program with
• New
• Name your program (no spaces or symbols)
• Choose Function or Program

Remember that you must  pick function or program correctly as you cannot change it later.

### Useful functions

• Disp — displays output — Menu,  6, 1
ex: Disp “Hello, world!”       Hello, world!
Disp x                                42
• Mean — calculates the mean of a list of values
ex: Mean({3,4,5})                     4
• Abs — calculates absolute value of a number or members of a list
ex: abs({-3,4,-5})                   {3,4,5}
|{-3,4,-5}|                        {3,4,5}
• String — converts a number to a string to allow concatenation
ex: String(42)              42
Disp “It took ” & string(guesses) & ” tries.”

### Variables

• Variables must be declared before use
• Variables can be global or local, but we will only use local
• Local variables exist only inside your program
• Don’t confuse the assignment operator, := , with the comparison operator, =

### Parameters/Arguments

• Your program may accept parameters
• Parameters can be
• Numbers
• Lists
• Text
• If the parameter is the wrong type (or missing),

### Lists

• Lists are created using curly braces {}
• Lists can contain other objects like text or numbers
• The calculator has a number of functions like Mean, Median, etc. that operate on lists
• To access a specific member of a list, use listname[position]
ex: x := {5,6,7,8}                                       {5,6,7,8}
x[2]                                                          6

# Day 1 Program — MAD

Find the MAD of a list like {1,2,3,4,5}

```Define mad(values)=
Func
Local mean_values, distances, result

mean_values := Mean(values)

distances := Abs(mean_values - values)

result := Mean(distances)

Return result

```

Run and see what happens…

```mad({1,2})      .5

# Day 1 Program — F to C

This function took a temperature in Fahrenheit as input and output in Celsius.

```Define f2c(f)=
Func
Local c
c := 5/9*(f-32)
Return c
EndFunc```

Some examples:

```f2c(212)               100
f2c({32,68,98.6,212})   {0,20,37,100}```