Complete the code to assign the value 10 to variable x.
x <- [1]The variable x is assigned the numeric value 10 using the assignment operator <-.
Complete the function to return the value of y defined outside the function.
y <- 5 my_func <- function() { return([1]) }
The function returns the variable y which is defined outside the function, demonstrating lexical scoping.
Fix the error by completing the code to access the outer variable a inside the function.
a <- 3 outer_func <- function() { inner_func <- function() { return([1]) } inner_func() }
The inner function accesses the variable a from the outer scope, showing lexical scoping.
Complete the function to compute compound interest using the outer 'rate' variable.
rate <- 1.05 compound_interest <- function(principal) { return([1]) }
The function uses rate from the outer scope via lexical scoping to compute the interest correctly without hardcoding the value.
Complete the function to use the outer 'exponent' despite the local shadowing variable.
exponent <- 3 power_calc <- function(base) { exponent_local <- 2 return([1]) }
exponent_local.Lexical scoping allows access to the outer exponent (3), ignoring the local exponent_local (2), so 2^3 = 8.