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. Which of the following is a valid assignment operator?
a) +=
b) -=
c) *=
d) All of the mentioned

Answer: d [Reason:] Assignment operators are +=, -=, *=, /=, **=.

2. What does the **= assignment operator do?
a) Multiplies the value twice
b) It is used as exponent like 2**3=8
c) It is the multiplication operator.
d) None of the mentioned

Answer: b [Reason:] a**=2 means a to the power of two.

3. What is the output of the given code?

```counter = 2
while counter < 68
puts counter
counter**=2
end```

a) 2 4 16 64
b) 2 4 16
c) 2 4 16 256
d) None of the mentioned

Answer: b [Reason:] The counter will increment by the power of two.

```Output:
2
4
16```

4. What is the output of the given code?

```counter = 1
while counter < 11
puts counter
counter+=1
end```

a) 1 2 3 4 5
b) 1…10
c) 1..10
d) None of the mentioned

Answer: c [Reason:] 1..10 inclusive 10 also. The counter will increment by one.

```Output:
1
2
3
4
5
6
7
8
9
10```

5. Ruby does not support ++ operator, it only supports += operator.
a) True
b) False

Answer: a [Reason:] Ruby does not support ++ or — operator. It only supports += or -= operator.

6. What is the output of the given code?

```counter = 100
while counter > 0
puts counter
counter/=5
end```

a) 100 20 4
b) 100 20 5
c) 100..5
d) None of the mentioned

Answer: a [Reason:] First counter will be 100 then after division it will become 20 then again it will become 4 and then it will come out of the loop.

```Output:
100
20
4```

7. What is the output of the given code?

```counter = 100
while counter > 0
puts counter
counter-=25
end```

a) 100 75 50 25
b) 100 25 5
c) 100..5
d) None of the mentioned

Answer: a [Reason:] The counter value will decrement by 25.

```Output:
100
75
50
25```

8. What is the output of the given code?

```counter = -50
while counter <0
puts counter
counter+=10
end```

a) 100 75 50 25
b) -50 -40 -30 -20 -10
c) 100..5
d) None of the mentioned

Answer: b [Reason:] The counter value will decrement by 10 till the counter value reaches zero.

```Output:
-50
-40
-30
-20
-10```

9. The given two expression means the same.

`counter=counter+1 and counter++`

a) True
b) False

Answer: a [Reason:] Both the expression increments the value by 1.

10. What is the output of the given code?

```a = 22.5
while a >11.5
puts a
a-=3.5
end```

a) 22.5 19.0 15.5 12.0
b) 22.5 11.5
c) 100..5
d) None of the mentioned

Answer: b [Reason:] The counter value will decrement by 3.5 till the counter value reaches 11.5.

```Output:
22.5
19.0
15.5
12.0```

11. What is the output of the given code?

```a = 5
b=10
while a <10 && b<20
puts a+b
a+=2
b+=2
end```

a) 10 20
b) 15 19 23
c) 15 16 17 18 19 20
d) None of the mentioned

Answer: b [Reason:] The counter value will increment by two till a<10 and b<20.
```Output:
15
19
23```

12. What is the output of the given code?

```a = 5
b=10
while a <10 && b<20
puts a*b
a+=2
b+=2
end```

a) 10 20
b) 15 19 23
c) 50 84 126
d) None of the mentioned

Answer: c [Reason:] The counter value will increment by two till a<10 and b<20 and multiply a and b.
```Output:
50
84
126```

13. What is the output of the given code?

``` a= 5
b=10
while a <10 && b<20
puts a-b
a+=2
b+=2
end```

a) 10 20
b) 15 19 23
c) -5 -5 -5
d) None of the mentioned

Answer: c [Reason:] Even if both the values are incremented by two the difference remains the same.

```Output:
-5
-5
-5```

14. What is the output of the given code?

``` a = 5
b=10
while a <10 || b<20
puts a*b
a+=2
b+=2
end```

a) 10 20
b) 50 84 126 176 234
c) -5 -5 -5
d) None of the mentioned

Answer: b [Reason:] The while will keep on executing even if only one condition is true.

```Output:
50
84
126
176
234```

15. What is the output of the given code?

``` a = 5
b=10
while (a <10 || b<20)&&true
puts a*b
a+=2
b+=2
end```

a) 10 20
b) 50 84 126 176 234
c) -5 -5 -5
d) None of the mentioned

Answer: b [Reason:] The while will keep on executing when both the conditions are true.

```Output:
50
84
126
176
234```

### Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com

.woocommerce-message { background-color: #98C391 !important; }