Recap - True or False
Part of the Fundamentals section of Coddy's R journey — lesson 32 of 78.
Challenge
EasyRead 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:
- 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: FALSEIf the input is FALSE, the output should be:
Opposite: TRUETry 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
4Operators Part 2
Logical Operators (AND, OR)Logical Operators Part 2 (NOT)Recap - Simple LogicVectorized Logic Part 1Vectorized Logic Part 22Variables and Data Types
Numeric Data TypeInteger Data TypeCharacter Data TypeLogical Data TypeChecking Data TypesNaming ConventionsMissing Values: NARecap - Variable Creation8Loops
For LoopWhile LoopBreakNext (Continue)Recap - FactorialSequence Generation (seq, :)Nested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsInteger Division and ModuloAssignment OperatorsRecap - Simple MathComparison Operators6Basic IO
Print OutputCat for OutputOutput With VariablesReading Input with readline()Type Conversion BasicsRecap - Age CalculatorRecap - True or False9Functions
Declaring a FunctionFunction ArgumentsReturn ValuesRecap - Sigma FunctionRecap - Validation FunctionDefault Parameter Values