2015-10-05 Lab03

posted Oct 5, 2015, 4:52 AM by Samuel Konstantinovich   [ updated Oct 5, 2015, 8:02 AM ]
Goal: More If statements, also Boolean functions

HW08 has been updated

Do Now:
(isEven n) -> #true when n is even, #false otherwise


boolean functions should not use if statements.

If statements can be used to make more than 2 choices by combining them.

(if boolean
    expression1
    expression2)

An if statement is an expression so you can put an if inside of an if:
(if  you_have_cake_ingredients
     (if  you_can_bake
          (go_bake_a_cake)
          (go_learn_to_bake)
    (go_buy_cake_stuff)  ) )
we can see that variables like you_have_cake_stuff must be either true or false.
the things with parenthesis are commands (go_...) 

code example:
(if (> x 3)
    x
    (if (x >= 0)
        (+ 3 x)
        (- x) )  )  

We can return words too!
(if (x > 3)
    "Big"
    "Small")

would show you a value either: (Quotes show up when typing text as a value in computer languages, and when you print it in scheme)
"Big"
OR
"Small"
but never both.

Try to make a function:
(calcGrade n) Where n is your grade, you get different results:
>= 90 : "Pass"
70-90 not including 90: "Fail"
<70 : "Disown"

(define calcGrade (lambda (n )
     ????  
 )


Lab 03:
(isBetween a b n)  where a b and n are all numbers.
    #true when n is strictly between (not equal) a and b.
    #false otherwise

(xor a b)  where a and b are #true , or #false
    #true when a and b have different truth values.
    #false otherwise

Comments