gpt4 book ai didi

r - 询问〜特殊〜并返回答案的函数

转载 作者:行者123 更新时间:2023-12-04 04:15:10 26 4
gpt4 key购买 nike

我想这样做,但到目前为止,我所拥有的只是:

print("Will you go out with me?")

我希望代码能够正常工作,以便人们可以回答“是/否”,如果回答是"is",则将返回一条消息,例如时间,地点等。

我要问的人是R大师,所以对他们来说意义重大~~(:

希望有帮助。试图得到那个日期!

最佳答案

将以下内容放入文件中,然后请您的 friend 提供该文件的来源。

r <- readline("Will you go out with me? (respond 'yes' or 'no'): ")
if(grepl("[Yy]es", r)) {
cat("Date: 3/10/2018", "Time: 7pm", "Place: McDonalds", sep = "\n")
} else {
cat("Too bad, I'm a catch.")
}

现在,您的 friend 获取文件和BOOM,日期!
> source('~/.active-rstudio-document')
Will you go out with me?: yes
Date: 3/10/2018
Time: 7pm
Place: McDonalds

...或BOOM,被拒绝!
> source('~/.active-rstudio-document')
Will you go out with me?: no
Too bad, I'm a catch.

关于r - 询问〜特殊〜并返回答案的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49215499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com