126k views
0 votes
Write an if statement that prints the message ""The number is not valid"" if the variable distance is outside the range 100 through 2000(both inclusive).

1 Answer

5 votes

Answer:

The solution code is written in Python:

  1. if(distance < 100 or distance > 2000):
  2. print("The number is not valid")

Step-by-step explanation:

In this question either one of the two conditions (distance < 100 or distance > 2000) is met, the error message should be generated. Python offers the "or" keyword as a logical operator. The "or" keyword will join two conditions and so long as one of them is True, the final outcome will be evaluated to True. For example, if distance = 90 the error message will be printed. If distance is 2500, the error message will also be printed.

User Matthew Daumen
by
6.3k points