Westward Thinking
Westward Thinking

Reputation: 11

How do I explain boolean into English?

I have a question that deals with Booleans and || or. I was able to write this program correctly, but I am having trouble putting into English why when you have both inputs as false, the answer is false. If it is not raining or it is not snowing, the weather can still be bad.

INPUT[1] is true if it is raining.

INPUT[2] is true if it is snowing.

Write a program that returns true if the weather is bad. (We will consider it's bad weather if it's not sunny).

Tip: you can return boolean variables or expressions directly, sometimes an if else statement is not needed.

var Rain = INPUT[1]

var Snow = INPUT[2]

return Rain || Snow

Upvotes: 1

Views: 124

Answers (1)

Harrison Jones
Harrison Jones

Reputation: 2506

You didn't specify a programming language, so just speaking logically you have the following criteria:

Rain = TRUE if it is raining

Snow = TRUE if it is snowing

and you have the following definition of Weather:

Weather = Rain || Snow

In this question, there are no other variables that can impact the Weather variable, which means that the weather has to be good (i.e. Weather = FALSE) if it's both not raining (Rain = FALSE) and not snowing (Snow = FALSE).

Regarding your comment:

If it is not raining or it is not snowing, the weather can still be bad.

That is still possible because when you say:

If it is not raining OR it is not snowing

this is just an or statement. The other condition can still be TRUE in which case Weather will also be TRUE.

Upvotes: 1

Related Questions