What is the issue? Why output is not 1. | Sololearn: Learn to code for FREE!


What is the issue? Why output is not 1.

Code:- a = bool(input("f1: ")) b = bool(input("f2: ")) print(a+b) Output:- f1: True f2: False 2

8/7/2022 4:31:50 PM

Anshul Khangar

2 Answers

New Answer


the reason of this behaviour is NOT because input() functions returns always True. input function returns always a string. the input we give in the sample code is `True` and `False`. this is a string, and not a real boolean value. any non-empty string is considered as a `truthy value`, so when we use `bool()` to convert our input it returns True, which is a value of 1. we can input whatever string we like, the result will always be 1 for each of the input. the result of 1 + 1 = 2 so if we input: `eggs and spam` `tomato` the result will be same, as both are non-empty strings


Anshul Khangar Because input() function always returns String so bool(String) will be always True So bool(input()) = 1 So a = 1 + 1 = 2