Question

In: Computer Science

Hello. Please answer the following question in Scheme. Not Python, not any form of C, but...

Hello. Please answer the following question in Scheme. Not Python, not any form of C, but in the language Scheme. If you do not know Scheme, please do not answer the question. I've had to upload it multiple times now. Thank you.


1.2 Write a function called countdown that takes a positive integer and uses a do expression to display a sequence of numbers counting down to 1, each on its own line, then displaying the string "Blastoff!".
> (countdown 5)

5

4

3

2

1

Blastoff!

Solutions

Expert Solution

The code below will work for you.

(define num (read))
(define countdown (lambda (n)
         (if (= n 0)
             (display "Blastoff!")
             (
                 (display n)
                 (newline)
                 (countdown (- n 1)))
             )))
(countdown num)
(newline)

Explanation:

The first line of code will define a variable with name "num" and read an input from the user.

(define num (read))

then the next line define a lambda function with name "countdown()" which take "num" as an argument

(define countdown (lambda (n)

and from the next line the body of the function will start in which the first line will check if number is equals to zero, if it is true the the function will print "Blastoff!" other wise function will display the number first then decrease the value of number and recursively call it self with the new value of number.

(if (= n 0)
(display "Blastoff!")
((display n) (newline) (countdown (- n 1))))))

then the next line consist of incial call to the function countdown() with value in the variable "num"

(countdown num)

and the aditional last line will apen an extra new line in the output.

(newline)

Thank you..


Related Solutions

Hello. Please answer the following question in Scheme. Not Python, not any form of C, but...
Hello. Please answer the following question in Scheme. Not Python, not any form of C, but in the language Scheme. If you do not know Scheme, please do not answer the question. I've had to upload it multiple times now. Thank you. 4 Write a recursive function called mergesort that sorts a list by doing the following: (a) Use split to split the list into two roughly equal-sized partitions. (b) Recursively sort both partitions. (c) Use merge to merge the...
Hello there , can any one please find an answer for this question Q. a single...
Hello there , can any one please find an answer for this question Q. a single lossless dielectric slab of a thickness “d” and permittivity “ε2” is inserted between two regions. the first region is the free space and the second one is a lossless dielectric material of permittivity “ε3”. a uniform plane wave propagating in y- direction and polarized in z-direction is normally incident on the first region. derive an analytical expression for the total reflection coefficient and the...
HELLO, PLEASE ANSWER THE FOLLOWING QUESTION. IT WAS ASSIGNED WITH 2 PARTS. THANKS 42A) A company...
HELLO, PLEASE ANSWER THE FOLLOWING QUESTION. IT WAS ASSIGNED WITH 2 PARTS. THANKS 42A) A company uses the periodic inventory system and had the following activity during the current monthly period. November 1: Beginning inventory 112 Units @ $20 November 5: Purchased 112 Units @ $22 November 8: Purchased 62 Units @ $23 November 16: Sold 174 Units @ $105 November 19: Purchased 75 Units @ $25 Using the weighted-average inventory method, the company's ending inventory would be 42B. A...
Please answer the following question in a paragraph form address the issue of the stakeholder perspective...
Please answer the following question in a paragraph form address the issue of the stakeholder perspective and provide recommendations on how this industry should proceed in regards to self-driving trucks. 1. Apply the Three Levels of Stakeholder framework, from Business Ethics A Managerial Approach. book to this case. Discuss how the stakeholders involved should consider this innovation based on this framework. 2. Include recommendations on how decisions that regard the use of innovations such as the self-driving truck have on...
Hello, Please follow and answer the requirement on these question based on the case company which...
Hello, Please follow and answer the requirement on these question based on the case company which is Samsung. a) What is the organizational structure for Samsung Company (centralized or decentralized)? specific case information. (250 words)
Hello, please answer this question The nurse wants to search for information about a new medication...
Hello, please answer this question The nurse wants to search for information about a new medication that is in the testing phase of production. Which action should the nurse take when conducting a literature search about this medication? Select all that apply. A) Formulate a definition of the problem B) Ask a nurse colleague for help C) Identify the information D) Conduct a search of the most recent literature E) Skimming journal articles during lunch break
hello , could you please answer this question for me in details , my teacher want...
hello , could you please answer this question for me in details , my teacher want more than 400 word ?. it is an essay . 1) Discuss the application of Classical conditioning in reducing Anxiety.!!
Hello, please answer this question Compare and contrast the two major causes of hemolytic disease of...
Hello, please answer this question Compare and contrast the two major causes of hemolytic disease of the newborns.
Hello, could you please provide a detailed answer to below question? Question: Given all time low...
Hello, could you please provide a detailed answer to below question? Question: Given all time low interest rates, companies should borrow long term and use the borrowed money to takeover other firms. Discuss with suitable reasons, citing empirical evidence, whether you agree or disagree with this statement.                
Answer please the Question below - in WRITTEN FORM ONLY PLEASE 2) In a 1953 study...
Answer please the Question below - in WRITTEN FORM ONLY PLEASE 2) In a 1953 study of stock prices, what did Maurice Kendall find and what does it mean in terms of the EMH? Explain 2.1) Even if the markets are efficient, you can find a job as a professional portfolio manager. How is that possible?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT