a大于1,b小于1000。如何在R控制台中输入a和b,而不是在R脚本中定义?我已经阅读过有关readline函数的信息,但并不太了解。
a <- 3
b <- 4
y <- a*b
y
if((y %% 2) == 0) {
print(paste(y,"is Even"))
} else {
print(paste(y,"is Odd"))
}
答案 0 :(得分:0)
您可以使用 property "bad project value" do
[user, project] = prepare()
project_gen = constant("project_id")
|> map_of(Factory.my_terms, length: 1)
tasks = List.duplicate(%{"asset_id" => 10, "tasks" => []}, 2)
tasks = %{"tasks" => tasks}
check all project <- project_gen do
params = Map.merge(project, tasks)
res = ProjectTask.Save.save(params, %{id: user.id})
assert res == {:error, :not_found}
end
end
功能。
示例:
readline()
答案 1 :(得分:0)
只需使用readline
更改前两行并将整个内容包装在{}
中,就可以将脚本合并为子句。
{
a <- as.numeric(readline(prompt = "Enter a: ")) # Read in from console and change to number
b <- as.numeric(readline(prompt = "Enter b: ")) # Read in from console and change to number
y <- a*b
y
if((y %% 2) == 0) {
print(paste(y,"is Even"))
} else {
print(paste(y,"is Odd"))
}
}
这使您可以从上到下运行整个过程,并连续进行输入。您也可以将其变成一个函数。