Select Page
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

1. Boolean opeartors are also known as logical operators.
a) True
b) False

Answer: a [Reason:] Boolean operators result in boolean values like true or false.

2. Which of the following is a valid boolean operator?
a) and(&&)
b) or(||)
c) not(!)
d) All of the mentioned

Answer: d [Reason:] We have three boolean operators which are and, or, not.

3. The boolean operator && only result in true when both the values are true?
a) True
b) False

Answer: a [Reason:] The && operator only results in true when both the values are true rest all cases it evaluates to false.

4. What will the following expression evaluate to?
true && false
a) True
b) False
c) Error
d) None of the mentioned

Answer: b [Reason:] Boolean operator && evaluates to true only when both the values are true.

5. What will be the output of the given code?

```boolean_1 = 77 < 78 && 77 < 77
puts boolean_1```

a) True
b) False
c) Error
d) None of the mentioned

Answer: b [Reason:] 77<78 is true but 77<77 is false hence the overall expression will evaluate to false.
```Output:
False```

6. What will the following expression evaluate to?
true || false
a) True
b) False
c) Error
d) None of the mentioned

Answer: a [Reason:] Boolean operator || evaluates to true only when both the values are true or one is true and other is false.

7. What will the following expression evaluate to?
(true && false) || (!true)
a) True
b) False
c) Error
d) None of the mentioned

Answer: b [Reason:] Boolean operator && evaluates to true only when both the values are true and !true means false hence the whole expression will evaluate to false.

8. What will the following expression evaluate to?
!true && !false
a) True
b) False
c) Error
d) None of the mentioned

Answer: b [Reason:] Boolean operator && evaluates to true only when both the values are true.

9. What will be the output of the given code?

``` boolean_1 = (3 < 4 || false) && (false || true)
puts boolean_1```

a) True
b) False
c) Error
d) None of the mentioned

Answer: a [Reason:] 3<4 is true and true or false will evaluate to true hence the overall expression will evaluate to true.
```Output:
True```

10. What will be the output of the given code?

``` boolean_1 = !(3 < 4 || false) && (false || true)
puts boolean_1```

a) True
b) False
c) Error
d) None of the mentioned

Answer: b [Reason:] 3<4 is true and true or false will evaluate to true hence the overall expression will evaluate to true but the ! used will make the whole expression evaluate to false.
```Output:
False```

11. What will be the output of the given code?

``` boolean_1 = 2**3 != 3**2 || true
puts boolean_1```

a) True
b) False
c) Error
d) None of the mentioned

Answer: a [Reason:] 2**3=8 and 3**2=9 both the values are not equal is true and true or true will evaluate to true hence the overall expression will evaluate to true.

```Output:
True```

12. What will be the output of the given code?

``` boolean_1 = false || -10 > -9
puts boolean_1```

a) True
b) False
c) Error
d) None of the mentioned

Answer: a [Reason:] -10 is not greater than -9 hence the output will be false || false which is false.

```Output:
False```

13. What will be the output of the given code?

``` boolean_1 = !(700 / 10 == 70)
puts boolean_1```

a) True
b) False
c) Error
d) None of the mentioned

Answer: b [Reason:] 700/10=70 which is true but the ! before 700/10==70 will evaluate to false hence the overall expression will evaluate to false.

```Output:
False```

14. What will be the output of the given code?

``` boolean_1 = !true
puts boolean_1
boolean_2 = !true && !true
puts boolean_2```

a) True True
b) False False
c) True False
d) None of the mentioned

Answer: c [Reason:] !true = false and !true and !true will evaluate to false.

```Output:
False
False```

15. What will be the output of the given code?

``` boolean_2 = !true && (!true || 100 != 5**2)
puts boolean_2```

a) True
b) False
c) Error
d) None of the mentioned

```Output: