-1

I started learning python from a site, and it gave me a question that was kind of weird, I had to add and multiply a number to True and False. I've never done that before, so could someone explain what that means? (Can you replace True with 1 and False with 0?)

This is the question:

What is the value of result at the end of the following code?

x = 20
y = 5
result = (x + True) / (4 - y * False)
 

A) False

B) -21

C) 5

D) 5.25

itsanantk
  • 264
  • 1
  • 9
  • Please repeat [on topic](https://stackoverflow.com/help/on-topic) and [how to ask](https://stackoverflow.com/help/how-to-ask) from the [intro tour](https://stackoverflow.com/tour). We expect you to do initial research before posting here, especially trying some of your own coding. `print(True + 0)` would give you most of your desired information, as would looking up the integer values of Boolean constants. – Prune Sep 16 '20 at 17:05

1 Answers1

1

The answer is 5.25 because in Python, True is equal to 1 while False is equal to 0.

Leonardo
  • 272
  • 3
  • 16