问题描述
|
就像Magic-8球游戏一样,我正在尝试构建一个模型,该模型可以按以下顺序回答不同的问题:
\“可以肯定的是\”
\“前景良好\”
\“稍后再询问\\”
\\“前景不太好\\”。
如果问题为空,则产生“您没有提出问题,请重试”,表示为(无答案)
我为这个问题写下了代码,但是空的情况不起作用。
也就是说,“ 0”应产生“您没有问问题,请重试”。
;; 8-ball-answers: (listof string)
(define 8-ball-answers (list \"It is certain\" \"Outlook good\" \"Ask again later\" \"Outlook not so good\"))
;; no-answer: string
;; Purpose: correct form of string to produce when magic-8-ball consumes empty string
(define no-answer \"you did not ask a question,try again\")
;;magic-8-ball: string -> string
;;Purpose: consumes a string and produces a string
;;Effects: modifies (8-ball-answers). If the string is empty,produces
;; \"you did not ask a question,try again\". Otherwise,changes
;; \"It is certain\" to \"Outlook good\",;; \"Outlook is good\" to \"Ask again later\",;; \"Ask again later\" to \"Outlook not so good\",;; and \"Outlook not so good\" to \"It is certain\".
(define (magic-8-ball s)
(local
[
;; new-list represents the new value of the list 8-ball-answers
;; after every time the function is called.
(define next-answer (first 8-ball-answers))]
(begin
(cond [(equal? s \"\") no-answer]
[else (set! 8-ball-answers (append (rest 8-ball-answers)
(list next-answer)))])
next-answer)))
这是我的测试用例:
(check-expect (and (equal? (magic-8-ball \"Do you love me?\")
\"It is certain\")
(equal? (magic-8-ball \"How is your life?\")
\"Outlook good\")
(equal? (magic-8-ball \"\")
\"you did not ask a question,try again\")
(equal? (magic-8-ball \"2nd0A-wmQ232.asdA?\")
\"Ask again later\")
(equal? (magic-8-ball \"No questions here\")
\"Outlook not so good\")
(equal? (magic-8-ball \"Now do you hate me?\")
\"It is certain\"))
true))
测试应该通过,但是我没有通过。当字符串为空时,会发生此问题。
谁能告诉我问题是什么?
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)