+ 3

Can anyone suggest me?

I didn't find any other way to flip the boolean numbers...can anyone suggest me any other way to flip the boolean?? In Python only.👍 https://code.sololearn.com/cNiu3j4Lq2pj/?ref=app

13th Aug 2017, 4:52 AM
Girish Tulabandu
Girish Tulabandu - avatar
4 Answers
+ 3
a=input("Enter a boolean number:") print("the swapped boolean is:") for i in list(a): print (int(not bool(int(i))))
13th Aug 2017, 6:25 AM
Oscar Albornoz
Oscar Albornoz - avatar
+ 8
You can use regex to check the entire string for values other than 1 and 0, prior to iterating the string.
13th Aug 2017, 5:57 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
a=input("Enter a boolean number:") print(a) print("the swapped boolean is:") for i in a: if i =="1" or i == "0": print(0 if i == "1" else 1, end='') else: print("Give valid input")
13th Aug 2017, 5:14 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
@Hasty rei , I think you're sarcastic boy..I too did same thing bro....I need another logic..😁
13th Aug 2017, 5:17 AM
Girish Tulabandu
Girish Tulabandu - avatar