** How to call: **
police_trouble(a, b)
** Output example: **
police_trouble(true, false) → False
police_trouble(false, false) → True
police_trouble(true, true) → True
#true if both a and b are true
a && b
#true if either a or b is true
a || b
#false if a is true, true if a is false
!a
def police_trouble(a, b)
if (a && b) || (!a && !b)
puts "True"
else
puts "False"
end
end
police_trouble(true, false)
police_trouble(false, false)
police_trouble(true, true)
Logical operator in if statement&&When||When!Describe the conditional expression using a. 「(a && b) || (!a && !b)"Is ① Both a and b are true ② 〃 false In either case, "** True **" is output. Otherwise (if not meshing) output False.
Recommended Posts