Menu
Coddy logo textTech

Recap - Simple Logic

Part of the Fundamentals section of Coddy's Ruby journey — lesson 18 of 88.

challenge icon

Challenge

Easy

You are provided with the following variables:

age = 25
has_license = true
years_of_experience = 3
has_insurance = false
is_weekend = true

Combine comparison and logical operators to evaluate and display the following expressions, each on a separate line:

  1. Check if age is between 18 and 65 (inclusive) using &&
  2. Check if the person can drive: age is at least 18 and has_license is true
  3. Check if the person is an experienced driver: has_license is true and years_of_experience is greater than or equal to 2
  4. Check if the person needs insurance: has_license is true and has_insurance is NOT true
  5. Check if it's a good day to practice driving: is_weekend is true or years_of_experience is less than 1
  6. Check if the person is a qualified weekend driver: age is at least 21 and has_license is true and (is_weekend is true or has_insurance is true)

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 driver

All lessons in Fundamentals