-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.txt
More file actions
53 lines (40 loc) · 1.7 KB
/
weather.txt
File metadata and controls
53 lines (40 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
; Written by Sanjeeb Sangraula
; The Scheme program starts
; A method to display the weather condition of a place based on a list of temperatures
; Input - temps - a list containing the temperatures.
; It, temps, contains five integers that represent the current temperature, the normal high
; temperature the normal low temperature, the high temperature on that day the previous year, and the
; low temperature on that day the previous year.
(define (weather temps)
(cond
; Check if the temperature is hot
[(> (car temps) (car (cdr temps)))
; Define the first part of the output as p to print later
(define p "It is hot ")
; Another cond to compare current temperature with last year's temperatures
(cond
((and (> (car temps) (car (cdr temps))) (< (car temps) (car (cdddr temps))))
(print p "but not as hot as last year.")
)
(else (print p "just like last year."))
)
]
; Check if the weather is cold
[(< (car temps) (car (cddr temps)))
; Define the first part of the output as p to print later
(define p "It is cold ")
; Another cond to compare current temperature with last year's temperatures
(cond
((and (< (car temps) (car (cddr temps))) (> (car temps) (car (cddddr temps))))
(print p "but not as cold as last year.")
)
(else (print p "just like last year."))
)
]
; if the weather isn't hot or cold, and is between the hot and cold weather
[else
(print "It is nice just like last year.")
]
)
)
; The method Ends