Menu
Coddy logo textTech

Recap - True or False

Part of the Fundamentals section of Coddy's R journey — lesson 32 of 78.

challenge icon

Challenge

Easy

Read a string input representing a logical value, convert it to an actual logical value, then output the opposite value using the NOT operator.

You will receive one input:

  1. A string that is either "TRUE" or "FALSE"

Read the input using readline(), convert it to an actual logical value by comparing the string, then apply the NOT operator (!) to get the opposite value.

Display the result in the following format:

Opposite: [result]

Use cat() for the output and include a newline character \n at the end.

For example, if the input is TRUE, the output should be:

Opposite: FALSE

If the input is FALSE, the output should be:

Opposite: TRUE

Try it yourself

# Read input
input_string <- readline()

# TODO: Write your code below
# 1. Convert the input string to a logical value
# 2. Apply the NOT operator (!) to get the opposite value

# Output the result
cat("Opposite: ", result, "\n", sep = "")

All lessons in Fundamentals