Lab10 题解 (UCB CS61A@2021 Fall)
Q2: Over or Under
Define a procedure
over-or-underwhich takes in a numbernum1and a numbernum2and returns the following:
- -1 if
num1is less thannum2- 0 if
num1is equal tonum2- 1 if
num1is greater thannum2Challenge: Implement this in 2 different ways using
ifandcond!(define (over-or-under num1 num2) 'YOUR-CODE-HERE )
代码其实本身不难, 主要是适应 scheme 语言的写法, 条件分支有两种写法: