The MCQs are designed fo the "Making choices" section of Programming in R (http://swcarpentry.github.io/r-novice-inflammation/04-cond.html)
YouAreATeenAger <- function(Age)
{
if ((Age > 20) | (Age < 12)) {
teenager <- FALSE
} else {
teenager <- TRUE
}
return(teenager)
}
yourage <- 68
if (YouAreATeenAger(yourage)){
print("You are a teenager")
} else {
print("You are not a teenager")
}
What will be printed?
Now, you have to figure what this code makes:
WhatYouAre <- function(Age)
{
whatyouare <- "Senior"
if ((Age >= 20) & (Age <70)) {
whatyouare <- "Adult"
}
else if ((Age >= 13) | (Age < 20)) {
whatyouare <- "Teen Ager"
} else {
whatyouare <- "Kid"
}
return(whatyouare)
}
print(WhatYouAre(78))
print(WhatYouAre(45))
print(WhatYouAre(18))
What will be printed?
Explanation of the MCQ