Recap - Simple Logic
Part of the Fundamentals section of Coddy's Ruby journey — lesson 18 of 88.
Challenge
EasyYou are provided with the following variables:
age = 25
has_license = true
years_of_experience = 3
has_insurance = false
is_weekend = trueCombine comparison and logical operators to evaluate and display the following expressions, each on a separate line:
- Check if
ageis between18and65(inclusive) using&& - Check if the person can drive:
ageis at least18andhas_licenseistrue - Check if the person is an experienced driver:
has_licenseistrueandyears_of_experienceis greater than or equal to2 - Check if the person needs insurance:
has_licenseistrueandhas_insuranceis NOTtrue - Check if it's a good day to practice driving:
is_weekendistrueoryears_of_experienceis less than1 - Check if the person is a qualified weekend driver:
ageis at least21andhas_licenseistrueand (is_weekendistrueorhas_insuranceistrue)
Each output should be either true or false.
Try it yourself
# Variables provided
age = 25
has_license = true
years_of_experience = 3
has_insurance = false
is_weekend = true
# TODO: Write your code below
# Evaluate each expression and print the result (true or false)
# 1. Check if age is between 18 and 65 (inclusive) using &&
# 2. Check if the person can drive
# 3. Check if the person is an experienced driver
# 4. Check if the person needs insurance
# 5. Check if it's a good day to practice driving
# 6. Check if the person is a qualified weekend driverAll lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 42Variables and Data Types
Numbers and VariablesString Data TypeBoolean Data TypeSymbol Data TypeChecking Data TypesNaming ConventionsRecap - Variable Creation8Loops
For Loop with RangesWhile LoopBreakNextRecap - FactorialTimes LoopUntil LoopNested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators6Basic IO
Output with putsOutput with print and pOutput With VariablesInput with getsChomp MethodType ConversionRecap - Age CalculatorRecap - True or False