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

30th Jul 2020, 3:30 AM
Ruth
Ruth - avatar
3 Réponses
+ 2
30th Jul 2020, 5:40 AM
Oma Falk
Oma Falk - avatar
+ 1
b?
30th Jul 2020, 3:43 AM
HullaBrian
HullaBrian - avatar
+ 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.
30th Jul 2020, 4:57 AM
Bilbo Baggins
Bilbo Baggins - avatar