Menu
CoddyTech

Recap: Fare Bands

Lesson 12 of 48 in Coddy's R for Python Developers course.

challenge icon

Challenge

Easy

Input is one nonnegative age. Return fare 0 below age 5, 4 from 5 through 17, 7 from 18 through 64, and 3 at 65 or older.

Keep the declared public API. The visible locked driver checks it directly as well as printing solve(lines). Inputs satisfy the stated contract; all arithmetic is small and finite.

Your code goes in Functions.R and Exercise.R. main.R sources dependencies in order and holds the supplied input/output code; it cannot be edited.

Try it yourself

source("Functions.R")
source("Exercise.R")
stopifnot(identical(compute(17),4),identical(compute(66),3))
lines <- suppressWarnings(readLines(file("stdin"), warn=FALSE))
cat(solve(lines), "\n", sep="")

All lessons in R for Python Developers

Practice on your own: Online R compiler