Close
Close

Practice questions on Boolean and more

Level 1

1.
Take two inputs from user and check whether they are equal or not.
puts "Enter first number"
first = gets.chomp.to_i
puts "Enter second number"
second = gets.chomp.to_i
puts first == second

2.
Take 3 inputs from user and check :
all are equal
any of two are equal
( use && || )
puts "first number"
first = gets.chomp.to_i
puts "second number"
second = gets.chomp.to_i
puts "third number"
third = gets.chomp.to_i
all = first == second && second == third && third == first
puts "All are equal : #{all}"
any = first == second || second == third || third == first
puts "Any of three are equal: #{any}"

3.
Take two number and check whether the sum is greater than 5, less than 5 or equal to 5.
puts "Enter first number"
first = gets.chomp.to_i
puts "Enter second number"
second = gets.chomp.to_i
sum = first+second
puts "Sum is greater than 5 : #{sum>5}"
puts "Sum is equal to 5 : #{sum==5}"
puts "Sum is lesser than 5 : #{sum<5}"

4.
Judge the follwing expressions :
!(true && true)
true || false
!(false && true)
false && false
puts !(true and true)
puts true || true
puts !(false && false)
puts false && false

5.
Suppose passing marks of a subject is 35. Take input of marks from user and check whether it is greater than passing marks or not.
pm = 35
marks = gets.chomp.to_i
puts "Marks is greater than passing marks : #{marks>pm}"

Level 2

Level 3

Ask Yours
Post Yours