0
Boolean conversion in python
if isWater = bool(input("Is there water (True or False)")) if isWater == True: print("I will buy water") else: print("I will buy other drink") when will "I will buy other drink" be displayed? a, when the user enters 'false' b, when the user passes empty string c, when the user enters 'FALSE' d, no answer given
3 Réponses
+ 2
HullaBrian yes!
+ 1
b?
+ 1
First of all, remove the initial 'if', it is an error.
After that, we want isWater False, in order to print 'I will buy other drink'.
But cases (a) and (c) will give True, because every not-empty string is True.
Case (d) will hang the program..
The only correct answer is (b): an empty string converted to boolean returns False.