151k views
0 votes
Which of the following expressions represents a legal way of checking whether a value assigned to the "num" variable falls in the range 100 to 200 (inclusive)? a) 100 <= num <= 200 b) num >= 100 && num <= 200 c) num => 100 || num =< 200 d) num > 100 && num < 200

User Sinoohe
by
9.0k points

1 Answer

1 vote

Answer: The correct answer is:

b) num >= 100 && num <= 200

Step-by-step explanation:

Step-by-step explanation:

To check if a value assigned to the "num" variable falls in the range 100 to 200 (inclusive), we need to use logical operators and comparison operators in our expression.

Let's break down the given options:

a) 100 <= num <= 200: This expression is not valid in most programming languages. We cannot chain comparison operators like this. Instead, we need to split it into two separate conditions.

c) num => 100 || num =< 200: The symbols "=>" and "=<" are not valid comparison operators. The correct symbols are ">=" and "<=".

d) num > 100 && num < 200: This expression correctly checks if the value of "num" is greater than 100 and less than 200. However, the question asks for the range to be inclusive, which means the value can be equal to 100 or 200. So this option is not correct.

b) num >= 100 && num <= 200: This expression checks if the value of "num" is greater than or equal to 100 and less than or equal to 200. It correctly covers the inclusive range from 100 to 200.

In summary, the correct expression to check if a value assigned to the "num" variable falls in the range 100 to 200 (inclusive) is:

b) num >= 100 && num <= 200

User Michael Hoff
by
8.2k points